align, aligned and R Markdown

2018-01-31 06:03:01

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 .R

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

    $$

    2018-01-31 08:29:41