Search code examples
javascriptmathjax

Run mathjax on javascript string that is not present in the HTML


Mathjax typically finds specific elements in the page and specific strings in those elements (substrings delimited by $...$, for example) and alters those strings into nice HTML that looks pretty.

What is the underlying function that MathJax uses to convert those strings into nice HTML?

I would very much like to use that function because I need to run other things on the javascript strings before I actually render them on the page.


Solution

  • That is currently not possible as MathJax needs the DOM for its rendering process (e.g. font matching, webfont detection, in some situations measuring dimensions of subexpressions, and worse things on legacy browsers). You can create elements and not attach them before handing them to MathJax (in which case MathJax will attach them temporarily) but that comes with a small risk of CSS interfering.

    FWIW, we're planning to work on a more or less DOM-free rendering next year (since recent browser engines are more stable in terms of layout); cf. mathjax-node.

    Disclaimer (I guess) I'm a member of the MathJax team.