eric
eric

Reputation: 8088

Equation numbering between cells in Jupyter resets to 1

When I enter equations in Jupyter notebook markdown cell using Latex, it works great:

$$
\begin{equation}
\ddot{x} + a\dot{x} + bx = 0
\label{second_order_full}
\end{equation}
$$

This yields:

equation 1

Then I write out the equivalent system of equations:

$$
\begin{equation}
\begin{aligned}
&\dot{x} = y\\
&\dot{y} = -ay - bx
\end{aligned}
\label{second_order_normal}
\end{equation}
$$

yielding:

equation 2

But then when I enter info in a different markdown cell:

$$
\begin{equation}
\begin{aligned}
&\dot{x_1} = a_1x_1 + a_2x_2\\
&\dot{x_2} = a_3x_1 + a_4x_2
\end{aligned}
\label{normal2}
\end{equation}
$$

I get the following:

equation 3 oops

That is, the numbering has reset back at 1. This is all in the same Jupyter notebook. How can I fix this?

It happens just the same when I insert the following in a code cell:

%%javascript 
MathJax.Hub.Config({
    TeX:{equationNumbers:{autoNumber:'all'}}
});

I have also tried:

%%javascript
MathJax.Hub.Config({
    TeX: { equationNumbers: { autoNumber: "AMS" } }
});

Possibly related questions
Equation numbering in Jupyter notebooks
MathJax auto equation numbering does not work in Jupyter properly

Upvotes: 1

Views: 1106

Answers (1)

eric
eric

Reputation: 8088

After two years, I found the answer here:

https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/equation-numbering/readme.html

At the top of the notebook, put the following:

%%javascript
MathJax.Hub.Config({
    TeX: { equationNumbers: { autoNumber: "AMS" } }
});

Then using code like in the question, you will end up with numbers in each cell, but starting with 1 in each cell. To final step is you need to press the following reset equation numbering toolbar button that is in your Jupyter toolbar:

reset equation button

The equations all magically sort in order, voila!

Note if you aren't seeing the toolbar button, it means you haven't installed the equation number notebook extension. For instructions on how to install it, see this answer here:
https://stackoverflow.com/a/42940005/1886357

Upvotes: 3

Related Questions