5

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?

  • 6
    Welcome to TeX.SX! We have this question a lot of times. align is a full math environment, which must not be enclosed within (the deprecated!) $$ form or $. aligned on the other hand requires to appear in a math-mode enabling environment. I don't know why mathjax does allow this syntax, but pandoc uses LaTeX externally (as far as I know) and the error is reported. – user31729 Dec 24 '15 at 7:29
  • 1
    What does the R Markdown code look like to achieve the LaTeX output you show? – Werner Dec 24 '15 at 7:50
2

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}
$$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.