[Tex/LaTex] align, aligned and R Markdown

markdownpandocr

I have been working in R Markdown, which supports LaTeX, including in display mode. I had the following snippet for displaying aligned equations

$$
\begin{align}
a_1 &= \beta_0 \\
b_1 &= \beta_1 \\
c_1 &= \beta_2 \\
d_1 &= \beta_3
\end{align}
$$

This worked great for me when I chose to output as HTML. I believe this uses MathJax.

However, when I changed the output format to PDF, I get the following error message:

processing file: dummy.Rmd output file: dummy.knit.md

! Package amsmath Error: Erroneous nesting of equation structures;
(amsmath) trying to recover with `aligned'.

See the amsmath package documentation for explanation. Type H
for immediate help. …

l.87 \end{align}

pandoc: Error producing PDF from TeX source Error: pandoc document
conversion failed with error 43 Execution halted

When I change this to use aligned instead of align, it works with both.

This is an entire .Rmd file that shows the problem:

---
title: "dummy"
author: "Harold Ship"
date: "23 December 2015"
output: pdf_document
---


$$
\begin{align}
a_1 &= \beta_0 \\
b_1 &= \beta_1 \\
c_1 &= \beta_2 \\
d_1 &= \beta_3
\end{align}
$$

My question is, what is the difference between align and aligned, and why does align not work here with pandoc?

Best Answer

So, just to be clear (as it says this is unanswered), just write the align (without $$):

\begin{align}
a_1 &= \beta_0 \\
b_1 &= \beta_1 \\
c_1 &= \beta_2 \\
d_1 &= \beta_3
\end{align}

and not

$$
\begin{align}
a_1 &= \beta_0 \\
b_1 &= \beta_1 \\
c_1 &= \beta_2 \\
d_1 &= \beta_3
\end{align}
$$
Related Question