How to use eqnarray in R markdown to output html and pdf?

I cannot figure out how to use eqnarray to create equations in R markdown so that I can create both html and pdf output. This markdown R works for output_format='html_document' , but not output_format='pdf_document'

 My LaTeX equations $$ \begin{eqnarray} A &=& x \\ B &=& y \end{eqnarray} $$ 

For pdf output, this gives this error:

 ! Missing \endgroup inserted. <inserted text> \endgroup l.81 \begin{eqnarray} pandoc: Error producing PDF from TeX source Error: pandoc document conversion failed with error 43 

If I delete $$ , then this markdown R works for PDF output, but the equation is missing in the html output.

 My LaTeX equations \begin{eqnarray} A &=& x \\ B &=& y \end{eqnarray} 

Am I missing something? Is there a way to generate both PDF and html output from the same document?

+7
r r-markdown
source share
2 answers

I ran into the same problem and found that while eqnarray has the problems mentioned above, in the context of R markdown and knitr aligned environment works for both PDF output and HTML. Try the following:

 My LaTeX equations \begin{aligned} A &= x \\ B &= y \end{aligned} 

Note that there is only one & character and that it is the alignment operator in context for the aligned environment. aligned works a little differently than eqnarray , since it will be aligned in no more than one tab.

+8
source share

For Word output, this works:

 \[ \begin{aligned} A &= x \\ B &= y \end{aligned} \] 
+1
source share

All Articles