Equation numbers in blog posts with MathJax.

equations latex mathjax websites

How do you get MathJax to output equation numbers, and maybe reference them with a number and hyperlink?

Links:

I found the documentation a little confusing, I’ll note what I did that worked.

First, I set up a local configuration (MathJax configuration docs) by creating a file mathjax-config.js within a directory /js, so the full path is /js/mathjax-config.js. This file has the following contents:

window.MathJax = {
  tex: {
    tags: 'all'
  }
};

On a page where I want equation numbering, I have the following underneath the liquid header:

<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>

<script src="/js/mathjax-config.js" defer></script>
<script type="text/javascript" id="MathJax-script" async
  src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>
\[e^{\pi i} + 1 = 0 \label{eqone}\]

Let’s go back to Eq. \eqref{eqone}.

Let’s write another equation:

\[a + b = c \label{eqtwo}\]

Here I’m going to write some filler …. then make the window really short, so that you can test references, and …

And now I want to reference both Eq.s \eqref{eqone} and \eqref{eqtwo}.

To be honest, the equation references for the first equation work, but the reference goes to just below the second equation. So I’m still working on the reference part.

Update: on another page that is much bigger, and with more equations, the equation hyperlinks go to the right place.

The markdown for the above is:

$$e^{\pi i} + 1 = 0 \label{eqone}$$

Let's go back to Eq. \eqref{eqone}.

Let's write another equation:

$$a + b = c \label{eqtwo}$$

Here I'm going to write some filler .... 
then make the window really short, 
so that you can test references, and ...

And now I want to reference both Eq.s \eqref{eqone} and \eqref{eqtwo}.

© Amy Tabb 2018 - 2023. All rights reserved. The contents of this site reflect my personal perspectives and not those of any other entity.