Can we get MathML output from MathJax

I was wondering if there are ways to convert MathJax output to MathML .

I read several articles in which MathJax supports MathML . I also see the " Show MathML " option when I click on the MathJax formulas. My question is: can I get MathML output to a web page with MathJax ? I am not familiar with MathJax and I am not sure how this works. Any resources or training pages would be nice!

+4
source share
3 answers

@Peter, I think the OP may ask how to get a MathML string from MathJax, and not how to embed MathML tags directly on the page. Therefore, perhaps a discussion on the MathJax forums describing how to use toMathML will do the trick.

The main idea is to get the jax element (using MathJax.Hub.getAllJax ) for the math you want to convert, then call its toMathML method. But you need to take care of this a bit, since toMathML can work asynchronously. The link above details the details.

EDIT . The MathJax-node project allows you to do this from the command line, so you might want to check this as well.

+4
source

I wrote a verification code: First turn on " https://code.jquery.com/jquery-1.11.2.min.js " and " http://cdn.mathjax.org/mathjax/latest/MathJax.js?config= TeX-AMS-MML_HTMLorMML "

 var JaxToML = { toMathML: function(jax, callback) { var mml; try { mml = jax.root.toMathML(""); } catch (err) { if (!err.restart) { throw err } // an actual error return MathJax.Callback.After([JaxToML.toMathML, jax, callback], err.restart); } MathJax.Callback(callback)(mml); }, convert: function(AjaxText, callback) { var tempDiv = $('<div style="width:455px;height:450px:border-width:thick;border-style:double;"></div>').appendTo("body").html(AjaxText)[0]; MathJax.Hub.Queue(["Typeset", MathJax.Hub, tempDiv]); //first place in Q MathJax.Hub.Queue(function() { //wait for a callback to be fired var jax = MathJax.Hub.getAllJax(tempDiv); for (var i = 0; i < jax.length; i++) { JaxToML.toMathML(jax[i], function(mml) {//alert(jax[i].originalText + "\n\n=>\n\n"+ mml); AjaxText = AjaxText.replace(jax[i].originalText, mml); }); } $(tempDiv).remove(); AjaxText = AjaxText.replace(/\(/g,""); //notice this escape character for ( - ie it has to be \( , know why it is beacuse JS will treat ) or ( as end/begin of function as there are no quotes here. AjaxText = AjaxText.replace(/\)/g,""); //notice this escape character for ) - ie it has to be \) AjaxText = AjaxText.replace(/\\/g,""); callback(AjaxText); }); }, 

};

Using:

 JaxToML.convert(AjaxText, function(mml) { alert(mml); }); 
+1
source

The MathJax documentation on setting up MathJax is probably the place to start reading. You can customize jax output for browser .

A word of caution. There is a reason why MathJax is not used to output MathML in any browser right now: browser support is not yet at all. (This will change as browsers catch up, and MathJax may begin to use its own support.) So make sure your content really displays properly.

0
source

All Articles