浏览器显示MathML代码而不是方程式 [英] Browser to Display MathML code instead of equation

查看:63
本文介绍了浏览器显示MathML代码而不是方程式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何强制浏览器显示MathML代码而不是方程式吗?

Does any one know how to force browser to display MathML code instead of equation?

PS:将MathML渲染为纯文本格式可以看到TeX的输出.

PS: Rendering MathML to view as plain text gives the TeX output.

例如

(0,4)点所在的轴是_____

The axis on which the point (0,4) lie, is _____

应显示为:

<数学xmlns ="http://www.w3.org/1998/Math/MathML"<<语义><修剪>< mo Stretchy =假"(</mo> mn 0</mn> mo>,//mo> mn 4 4//mn< mo;/mo</mrow>注释注释="application/x-tex"(0,4)/注释/语义/数学_____

The axis on which the point <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo><mn>0</mn><mo>,</mo><mn>4</mn><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">(0, 4)</annotation></semantics></math> lie, is _____

推荐答案

在大多数常见配置中,如果您的输出不直接是mathML,则mathjax将mathml信息存储在span的属性 data-mathml 中标签wich包裹了mathJax元素

In most common configs, if your ouput is not directly mathML, mathjax stores mathml informations in the attribute data-mathml of a span tag wich wraps the mathJax element

这是当您右键单击mathJax元素时在弹出窗口中显示的内容:将数学显示为->MathMl代码

This is what is displayed in the popup when you right click on a mathJax element : show math as -> MathMl Code

如果您的目标是以mathml格式从html提取方程式,则可以创建一个脚本来解析文档并获取所有data-mathml属性.有很多方法可以实现这一点,这只是您可能需要调整的一个示例:

If your goal is to grab equations from html in mathml format, you can create a script which parse your document and get all data-mathml attributes. There is many ways to achieve that, this is just an example you may have to adapt:

function grabMathMl(){ 
    var spanMathMl = document.querySelectorAll(".MathJax");

    let results = [];
    let i = 0, ln = spanMathMl.length;
    for ( i; i < ln; ++i){
        if ( spanMathMl[i].hasAttribute("data-mathml") ){
 		        results.push(spanMathMl[i].dataset.mathml);
            // if you really want to replace content
            spanMathMl[i].innerHTML = "<textarea>"+spanMathMl[i].dataset.mathml+"</textarea>";
		    }
    }
    return results;
}

// put this fonction in the mathJax queue for you have to wait until mathJax process is done
MathJax.Hub.Queue(function(){
    let equations = grabMathMl();
    //console.log (equations.toString());// your equations in mathml
});

<script>
</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

<div>$$\left|\int_a^b fg\right| \leq \left(\int_a^b
	f^2\right)^{1/2}\left(\int_a^b g^2\right)^{1/2}.$$</div>

<div>
\begin{equation} x+1\over\sqrt{1-x^2} \end{equation}
</div>

那么,这个链接应该引起您的兴趣 https://superuser.com/questions/340650/在Microsoft词乳胶之路"中键入数学公式#802093

Then in word, this link should interest you https://superuser.com/questions/340650/type-math-formulas-in-microsoft-word-the-latex-way#802093

这篇关于浏览器显示MathML代码而不是方程式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆