Convert Latex/MathML to SVG or Image with mathjax or similar?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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 , or 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
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).