The elements must be attached to the DOM. MathJax needs to be able to measure the various subexpressions (so it can lay out things like fractions, etc.) and in order to do that, the container element for the mathematics must be in an active DOM. (Elements that aren't attached to the DOM don't have things like offsetWidth
calculated, so MathJax can't tell how big they are.)
If you want to have the mathematics typeset in an element before it is displayed, you can attach it to the DOM and set visibility:none
and position:absolute
, then call MathJax to typeset the element, and then remove the visibility and position settings. Don't use display:none
, as that also prevents MathJax from measuring elements.
See the examples from a talk I gave about this at the Joint Math Meetings in January 2013.