Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RMarkdown: Auto Number Equations

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}
like image 678
shredGnar Avatar asked Oct 29 '25 17:10

shredGnar


1 Answers

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.

like image 50
Ralf Stubner Avatar answered Oct 31 '25 10:10

Ralf Stubner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!