Search code examples
mathjax

MathJax error on second time render


I render dynamically the following code using MathJax:

When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$  

In equation \eqref{eq:sample}, we find the value of an interesting integral:
\begin{equation}
  \int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15}
  \label{eq:sample}
\end{equation}

using Hub.Queue

MathJax.Hub.Queue(["Typeset",MathJax.Hub]);

The first time the rendering works well. But when I try to render again using the same code only the first part is rendered, but the second part (which starts from \begin) does not parsed and shown in the black frame. Why it happens?


Solution

  • The problem is the use of \label. When the math is re-typeset, the label already exists (from the first typesetting), and so the TeX input jax reports that as an error (disable the noErrors extension to see the error message).

    You need to reset the labels (and presumably the equation numbers) before you typeset again. To do that, use

    MathJax.Hub.Queue(
      ["resetEquationNumbers",MathJax.InputJax.TeX],
      ["Typeset",MathJax.Hub]
    );
    

    instead of the MathJax.Hub.Queue(["Typeset",MathJax.Hub]) call.