Browser to Display MathML code instead of equation

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

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

For example,

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

Should be displayed as:

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 _____

Upvotes: 2

Views: 1987

Answers (1)

scraaappy
scraaappy

Reputation: 2886

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

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

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>

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

Upvotes: 2

Related Questions