4

How can I autonumber equations in an Rmarkdown document?

I've tried including "\usepackage{mathajax}" in the header, but the equations won't autonumber. I believe I need to configure mathjax, but can't figure out how.

I'm open to any solutions.

Please note, the solution in this post does not work.

Edit:

A simplified example of the desired output is below.

enter image description here

The code for the above image is below. I tried using \begin{equation} and \end{equation} instad of "align";however, the HTML document does not output the formulas correctly.

---
header-includes:
- \usepackage{amsmath}
output:
  html_document: default
---

\begin{align}
2+2 = 4 \tag{1} \\
3+2 = 5 \tag{2} \\
4+2 = 6 \tag{3} \\
5+2=7 \tag{4} \\
\end{align}
shredGnar
  • 149
  • 2
  • 11

1 Answers1

4

You can get pretty close by using bookdown::html_document2, c.f. the documentation:

---
output:
  bookdown::html_document2: default
---

\begin{align}
2+2 &= 4 \\
3+2 &= 5 (\#eq:three) \\
4+2 &= 6 (\#eq:four) \\
5+2 &= 7 (\#eq:five)
\end{align}

Result:

enter image description here

You get an equation number for every equation where you put a label. I have omitted the label on the first equation to show this effect. This is slightly different from the LaTeX's behavior, where you have to use \notag in an align environment to not get an equation number.

Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75