Not able to output to pdf, word and HTML with same Rmarkdown input

Viewed 257

So I am wishing to have a simple HTML, Word, and PDF output to a static R markdown document. It is below.

The script knits nicely to Word and HTML. But knitting to pdf gives the following error.

! Package amsmath Error: \begin{align} allowed only in paragraph mode.
Error: LaTeX failed to compile pdfissuesdoubeldollar.tex. See 
https://yihui.org/tinytex/r/#debugging for debugging tips. See 
pdfissuesdoubeldollar.log for more info

Now, I can take out both $$ and it will do the PDF and HTML knitting, but Word simply skips writing the equation. Using only a single dollar does not help either and that also has the issue of equations not getting centered on the page.

There are workarounds like making the word file and then using acrobat or save word file as PDF. But I am trying to automate the knitting of about 130 files and not have to maintain two separate files. Not having to maintain separate files was the only main reason for me to move from MSWord to Rmarkdown. I am willing to have a conditional R script with and without dollars but how can I capture which output format it is knitting to and how do I do so. Any help will be appreciated.

Rmarkdown script below

output:
  pdf_document:
    toc: no
    toc_depth: '4'
  html_document:
    toc: yes
    toc_depth: 4
    toc_float: yes
    theme: readable
  word_document:
    toc: no
    toc_depth: '4'


{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)


$$\begin{align} \in_{a} &= \frac{\text{Approximate Error}}{\text{Present Approximation}}\\ &= \frac{- 0.3830}{9.8800}\\ &= - 0.0388\end{align}$$
1 Answers

Usually I have always used \begin{split} instead of \begin{align} for LaTeX equations.

Related