Search code examples
latexr-markdownpdflatexxelatex

Rmarkdown render from script


I'm trying to knit an Rmd to pdf from a script so I can set an AWS service to generate reports, problem is, within Rstudio (knit button) it works fine but if I try to generate the document using rmarkdown::render('diagnostic.Rmd',output_format = pdf_document(latex_engine = "pdflatex"), output_file = "diagnostique.pdf")I get this error:

! Missing $ inserted.
<inserted text> 
                $
l.141 \$\ge
pandoc: Error producing PDF
Error: pandoc document conversion failed with error 43

Note that I'm using engine = pdflatexwhich produces the results I want, I've also tried xelatex and lualatex with success using lualatexwith a huge cost in quality (reports generated with lualatex do not compile as expected).

I have looked everywhere for this missing $without finding the mistake. Any advice on where to search or what to do would be much appreciated.


Solution

  • The error is TeX's error.

    So, line 141 mean line 141 of TeX file, not Rmd file.

    Keep your intermediate TeX file and check line 141 of it.

    YAML front matter is like this:

    ---
    title: "Title"
    output:
      pdf_document:
        keep_tex: true
    ---
    

    http://rmarkdown.rstudio.com/pdf_document_format.html#keeping_intermediate_tex