Jupyter Book uses MathJax for typesetting math in your HTML book build.This allows you to have LaTeX-style mathematics in your online content.This page shows you a few ways to control this.
This Jupyter Notebook cheat sheet will help you to find your way around the well-known Notebook App, a subproject of Project Jupyter. You'll probably know the Jupyter notebooks pretty well - it's one of the most well-known parts of the Jupyter ecosystem! Markdown for Jupyter notebooks cheatsheet. You can use Markdown to format documentation you add to Markdown cells in your Jupyter notebook. Here's how to format Markdown cells in Jupyter notebooks: Headings. Use the number sign (#) followed by a blank space for notebook titles and section headings: # for titles. ## for major headings.
See also
For more information about equation numbering,see the MathJax equation numbering documentation.
Tip
By default MathJax version 2 is currently used.If you are using a lot of math, you may want to try using version 3, which claims to improve load speeds by 60 - 80%:
See the Sphinx documentation for details.
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 attentionon more complex or longer equations, as well as link to them in your pages. To use a blockequation, wrap the equation in either $$
or begin
statements.
For example,
results in:
Latex-style math¶
You can enable parsing LaTeX-style math blocks with the amsmath
MyST extension. Enable it by adding the following to _config.yml
Once enabled, you can define math blocks like so:
which results in:
See also
The MyST guides to dollar math syntax, LaTeX math syntax, and how MyST-Parser works with MathJax.
For advanced use, also see how to define MathJax TeX Macros.
Numbering equations¶
Jupyter Latex Cheat Sheet
If you’d like to number equations so that you can refer to them later, use the math directive.It looks like this:
For example, the following code:
will generate
Alternatively you can use the dollar math syntax with a prefixed label:
which generates
Note
Labels cannot start with an integer, or they won’t be able to be referenced andwill throw a warning message if referenced. For example, :label:1
and :label:1eq
cannotbe referenced.
Linking to equations¶
If you have created an equation with a label, you can link to it from within your text(and across pages!).
You can refer to the equation using the label that you’ve provided by usingthe {eq}
role. For example:
results in
A link to an equation directive: (3)
A link to a dollar math block: (4)
Note
labels
inside LaTeX environment are not currently identified, and so cannot be referenced.We hope to implement this in a future update (see executablebooks/MyST-Parser#202)!
Jupyter line/cell magic commands
Conda
Images with defined size and caption
pdf2htmlEX
pdf2htmlEX --zoom 1.3 test.pdfpdf2htmlEX --embed cfijo --dest-dir out test.pdf
Markdown
md + LaTex
Inline syntax $e^{ix} = cos x + isin x$
outputs $e^{ix} = cos x + isin x$
Complex formulas.
I recommend to use <div>...</div> if you copy the code directly from LaTex. It's useful for text{...}
, align{...}
, and other commands which are not compiled correctly, even if you use $$...$$
. Also, works good with label{eq:equation1}
and eqref{eq:equation1}
, without the need to use tag{eq1}
.
md + referencing equations
Although label{eq:equation1}
and eqref{eq:equation1}
works good with <div>...</div>, the alternative is to use tags in Jupyter Notebook.
md + Embedded pdf
reStructuredText
rST + LaTex
Jupyter Display Latex
Inline syntax :math:`e^{ix} = cos x + isin x`
outputs (e^{ix} = cos x + isin x)