Search
Typesetting Math in your book

Jupyter Book uses MathJax for typesetting math in your book. This allows you to have LaTeX-style mathematics in your online content. This page shows you a few ways to control this.

For more information about equation numbering, see the MathJax equation numbering documentation.

In-line math

To insert in-line math use the $ symbol within a Markdown cell. For example, the text $this_{is}^{inline}$ will produce: $this_{is}^{inline}$.

Math blocks

You can also include math blocks for separate equations. This allows you to focus attention on more complex or longer equations, as well as link to them in your pages. To use a block equation, wrap the equation in either $$ or \begin statements.

For example,

\begin{equation}
  \int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15}
\end{equation}

results in

\begin{equation} \int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15} \end{equation}

and

$$
  \int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15}
$$

results in

$$ \int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15} $$

Numbering equations

MathJax has built-in support for numbering equations. This makes it possible to easily reference equations throughout your page. To do so, add this tag to a block equation:

\tag{<number>}

The \tag provides a number for the equation that will be inserted when you refer to it in the text.

For example, the following code:

equation 1
$$
  \int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15}
  \tag{1}
$$

equation 2

$$
  \int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15}
  \tag{2}
$$

equation 999

$$
  \int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15}
  \tag{999}
$$

Results in these math blocks:

equation 1 $$ \int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15} \tag{1} $$

equation 2

$$ \int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15} \tag{2} $$

equation 999

$$ \int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15} \tag{999} $$

Automatic numbering

If you'd like all block equations to be numbered with MathJax, you can activate this with the following configuration in your _config.yml file:

number_equations: true

In this case, all equations will have numbers. If you'd like to deactivate an equation's number, include a \notag with your equation, like so:

$$
  \int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15}
  \notag
$$

Linking to equations

Adding \label{mylabel} to an equation allows you to refer to the equation elsewhere in the page. You can define a human-friendly label and MathJax will insert an anchor with the following form:

#mjx-eqn-mylabel

If you use \label in conjunction with \tag, then you can insert references directly to an equation by using the \ref syntax. For example, here's an equation with a tag and label:

$$
\int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15}
\label{mylabel1}\tag{24}
$$

$$
\int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15}
\label{mylabel2}\tag{25}
$$
$$ \int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15} \label{mylabel1}\tag{24} $$$$ \int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15} \label{mylabel2}\tag{25} $$

Now, we can refer to these math blocks with \ref elements. For example, we can mention Equation \ref{mylabel1} using \ref{mylabel1} and Equation \ref{mylabel2} with \ref{mylabel2}.

Note that these equations also have anchors on them, which can be used to link to an equation from elsewhere, for example with this link text:

<a href="#mjx-eqn-mylabel2">My link</a>