3

I'm working on an RMarkdown document that I want to compile with xelatex using the shell escape option. The RStudio documents describe how this can be done for *.tex documents but the Enable shell escape command option does not appear to affect the compilation of Markdown documents.

Here's my YAML header. Is there a way I can pass the --enable-write18 option to the LaTeX engine by specifying it in the YAML?

---
title: "My document"
author: "Me"
date: "2016-01-01"
documentclass: report
output:
  pdf_document:
    latex_engine: xelatex
    number_sections: yes
    template: ard-pandoc-template.tex
    toc: yes
---

# Test

asdfjkhasdf
jkeirstead
  • 2,881
  • 3
  • 23
  • 26
  • Does this answer your question? [Latex shell-escape options in YAML header don't use](https://stackoverflow.com/questions/55459948/latex-shell-escape-options-in-yaml-header-dont-use) – robertspierre Apr 22 '23 at 15:39

2 Answers2

3

Found the answer on another RStudio page. There's an option to pass additional arguments to Pandoc from the YAML header:

output:
  pdf_document:
    latex_engine: xelatex
    pandoc_args: "--latex-engine-opt=--enable-write18"
jkeirstead
  • 2,881
  • 3
  • 23
  • 26
0

The solution provided by OP doesn't work anymore.

To have pdflatex called with -shell-escape in a RMarkdown document, put the following inside the document:

```{r, include=FALSE}
options(tinytex.engine_args = '-shell-escape')
```

The LaTeX engine is called by tinytex::latexmk() instead of Pandoc, so the Pandoc argument --pdf-engine-opt won't work.

Source (and credit) here.

robertspierre
  • 3,218
  • 2
  • 31
  • 46