I can't work out how to use eqnarray to create equations in R markdown such that I can create both html and pdf output. This R markdown 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 it 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 remove the $$
then this R markdown works for pdf output but the equation is missing from the html output.
My LaTeX equations
\begin{eqnarray}
A &=& x \\
B &=& y
\end{eqnarray}
Am I missing something here? Is there some way to generate both pdf and html output from the same document?
HTML documents can be attached to emails and viewed using any browser, even with no internet access (as long as it is a self-contained HTML document, which R Markdown exports usually are). PDF looks most professional when printed.
The following sections dive into the three components of an R Markdown document in more details: the markdown text, the code chunks, and the YAML header.
To indicate a superscript, use a single caret character ^ . Note: this can be confusing, because the R Markdown language delimits superscripts with two carets. In LaTeX equations, a single caret indicates the superscript. If the subscript or superscript has just one character, there is no need to delimit with braces.
I ran into the same problem and found that while eqnarray
has the problems mentioned above, in the context of R markdown and knitr
, the aligned
environment works for both PDF and HTML output. Try this:
My LaTeX equations
\begin{aligned}
A &= x \\
B &= y
\end{aligned}
Note that there is only one &
symbol here and that it's the alignment operator in the context for the aligned
environment. aligned
works a little differently to eqnarray
in that it will align at more than just one tab stop, so to speak.
For Word output, this works:
\[
\begin{aligned}
A &= x \\
B &= y
\end{aligned}
\]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With