Back to the Miscellaneous project page.
August 25, 2018
Blogging with Jupyter for Learning Julia Part 2
I’ve previously posted about Blogging with Jupyter in a previous post. For the latest post on LearningJulia I needed one additional feature: LaTeX equation numbering in Jupyter. Here’s how I got that to work.
Getting LaTeX Equation Numbering in Jupyter Notebooks
LaTeX natively supported in Markdown editing in a Jupyter notebook through MathJax. Getting it to work in Jupyter notebooks involves installing the jupyter_contrib_nbextensions
package.
These instructions are taken from the official install docs, and they worked for me.
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install user
jupyter nbextension enable equationnumbering/main
Then, restarting the jupyter kernel enables the extension. To get the numbered equations to show up in a markdown notebook, just use LaTeX syntax:
\begin{equation}
H u  v = 0
\end{equation}
\begin{equation}
\begin{bmatrix}
h_1 & h_2 & h_3 \\
h_4 & h_5 & h_6 \\
h_7 & h_8 & h_9
\end{bmatrix}\begin{bmatrix}
u_1 \\ u_2 \\ 1
\end{bmatrix}

\begin{bmatrix}
v_1 \\ v_2 \\ 1
\end{bmatrix} = 0
\end{equation}
This is the result!
The only downside of this extension is that every time you recompile a cell with equation numbering, the numbers keep incrementing. The good part is that the extension comes with a way to fix this problem: a little widget at the top of the notebook appears. When you click it, the numbering is restarted:
Pretty cool, right?
Getting LaTeX Equation Numbering in nbconvert
Automatically, nbconvert
will apply these new extensions. The one thing it won’t do is apply the correct MathJax settings in the style. To do that, all I needed was to add these lines:
<script type="text/xmathjaxconfig">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "AMS" }
}
});
</script>
to the exported .html
file after running nbconvert
. And the result works great!
You can read the full blog post here to learn what all these equations mean.
Conclusion
I hope this helps someone else, or at the very least, future me!
All Posts about Miscellaneous
2021 October 18  Favorite Podcasts 20192021
2020 February 9  Favorite Podcasts 20182019
2019 April 18  Lasercutter Memes
2018 October 26  Protecting Yourself Against rm
2018 September 3  Why I Left Amazon
2018 August 25  Blogging with Jupyter for Learning Julia Part 2
2018 August 17  Favorite Podcasts 20172018
2017 March 18  Blogging with Jupyter for Learning Julia
2017 February 15  Favorite Podcasts 20162017
2015 September 8  Installing Zim Wiki on OSX
2015 February 5  Word Frequency in the King James Bible
2014 February 13  A Fictional Middle East
2013 June 6  MIT Graduation Cap
2011 April 28  Playing Zork on Linux