I'm building a library that only allows objects render's functionality to to return DOM elements of the representation of themselves, one of those is math, so <img>
, <canvas>
or <svg>
will do it, I'll prefer svg.
Mathjax is known for being very good at this, but I need something more like:
Mathjax.Latex('\frac{2}{1}').toSVG(); //svg DOM node or string
Mathjax.Latex('\frac{2}{1}').toImage(); //Image, img node, or base64
I know it's possible with mathjax-node, but is it with mathjax client side? https://github.com/mathjax/MathJax-node
There is not built-in method for this. But you could obviously build something.
Here's a quick and dirty example. Note that this example configures MathJax to not use its globalCache for SVG paths; this makes the SVG output easily re-usable. There are also some caveats for rendering detached DOM nodes; MathJax will have to guess the context (CSS, font metrics etc).