Typeset math in SVG via MathJax 3

MathJax 3 has the ability to convert TeX directly to SVG. This is handy when embedding embedding typescript expressions into SVG, as you can simply insert the output from MathJax.tex2svg directly into your larger SVG document. As a result, if you use Observable’s “Download SVG” facility or SVG Crowbar on an HTML page, the typeset mathematics should be included correctly. Here’s an example:

Note that MathJax was long by far the best option to place typeset mathematics in web pages but has recently been challenged by KaTeX - largely due to the speed difference. I also like KaTeX’s API compared to MathJax 2. MathJax 3 is a big step forward on both those issues and still maintain’s a strong lead in feature implementation. One major issue with MathJax 3 is that the documentation is currently way behind the capabilities.


Cool! I didn’t realize that you could require MathJax 3. You can see the ugly thing I did in this notebook:

Thanks. The require is a bit awkward; Tom calls it “The ‘global leak’ pattern.” in his Module require debugger. I guess the idea is that MathJax adds a property to document.window which we then return via catch.