3

I'm trying to render math equations from user input server side using MathJax in Node.js. I'm using a separate library (mathjs) to turn the input into LaTeX, but after spending an hour looking at the MathJax docs I'm no closer to turning the LaTeX into MathML.

I'm assuming I'd be using the mathjax package on NPM, and then use the MathJax.InputJax and MathJax.OutputJax classes to do the processing, but I've got no idea how to put everything together.

(In case anyone is wondering, I'm using a CSS file to polyfill MathML, rather than load MathJax in the browser and cause a delay while the processing happens.)

Thomas Foster
  • 1,303
  • 1
  • 10
  • 23

1 Answers1

4

You want to use MathJax-node for this. It is set up to run MathJax server-side. There are a number of example command-line tools in the bin directory. You could also hook up a web service to handle the conversion. Tim Arnold made one available as mathjax-server on npmjs.com.

Davide Cervone
  • 11,211
  • 1
  • 28
  • 48
  • Thanks, I'll have a deeper look at those two repos. – Thomas Foster Mar 21 '15 at 12:49
  • MathJax v3 now can run in node directly, so MathJax-node is no longer necessary. See the [MathJax node demos](https://github.com/mathjax/MathJax-demos-node) repository for examples. – Davide Cervone Apr 27 '21 at 21:43
  • Is there any way to convert LaTeX to MathML in React application (client-side)? – Bhuvan Gandhi Feb 24 '22 at 05:45
  • @BhuvanGandhi, if you are trying to obtain the MathML representation but not insert it into the document, you could simply load MathJax v3 and use its `MathJax.tex2mml()` function to get the MathML (serialize it using `MathJax.startup.toMML()`. If you need to insert the MathML into the document, you would probably need to use one of the [MathJax react libraries](https://www.npmjs.com/search?q=mathjax%20react) and modify it to use MathML output as in the [example](https://docs.mathjax.org/en/latest/output/mathml.html#nativemml) in the docs. – Davide Cervone Feb 24 '22 at 12:35
  • Yeah, I have used `tex2mmlPromise()` function to convert LaTeX to MathML, thanks. You are doing a great job! – Bhuvan Gandhi Feb 24 '22 at 14:31