jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.73k stars 4.97k forks source link

notebook renders equations with labels correctly on first execution, but not on reexecution #2461

Open mpacer opened 7 years ago

mpacer commented 7 years ago

If I open a notebook with the following content


## Important Part

It is well known <cite data-cite="Atr03">(?)</cite> that Spice grows on the planet Dune.  Test
some maths, for example $e^{\pi i} + 3 \delta$.  Or maybe an
equation on a separate line:

$$g(x) = \int_0^\infty f(x) dx$$

or on multiple, aligned lines:

\begin{eqnarray} \\
   g(x) &=& \int_0^\infty f(x) dx \\
        &=& \ldots
\end{eqnarray}

The area of a circle and volume of a sphere are given as

\begin{equation} \label{circarea}
A(r) = \pi r^2.
\end{equation}

\begin{equation} \label{spherevol}
   V(r) = \frac{4}{3} \pi r^3
\end{equation}

It is first rendered as:

image

But then if it is rerendered (i.e., going into editing mode and then rerendering the cell) it is then rendered as:

image

If one refreshes the page it returns to the first state (even with a soft refresh).

@gnestor @takluyver @carreau @minrk Why would there be a difference between the first time something is rendered and the second from a MathJax perspective? I know there is weirdness around this kind of thing for numbering equations, but as long as we aren't running into that I have no idea where to start thinking about solving this bug.

minrk commented 7 years ago

My guess is that MathJax either doesn't know or doesn't handle the fact that the previous instance of the equation is gone and there there is a latex error assigning a duplicate label the second time. You will see probably related issues if you enable equation numbering, where the numbers are correct on first load, but each render of a cell increments equation numbers, rather than taking into account their location in the document.

There may be something we can do to tell mathjax explicitly that the equations have been removed, or trigger a more expensive re-process of the entire document on every render (or explicitly).

jtpio commented 1 year ago

Just checked and it still seems to be an issue with Notebook 7 / JupyterLab 4:

https://github.com/jupyter/notebook/assets/591645/80fa8f50-b15d-46e6-a1fb-3bf666833d4d

image