Render() does not pass -shell-escape arguments from pandoc to pdflatex



I want to render an Rmarkdown file that requires the -shell-escape option in pdflatex or --pdf-engine-opt=-shell-escape option in pandoc. I specified pandoc_args: "--pdf-engine-opt=-shell-escape" in my YAML header, but rmarkdown::render() seems to call programs in this order:

  1. knitr::knit() to *.md
  2. encoding conversion to *
  3. pandoc to *.tex (pandoc --to latex --output mwe.tex ...)
  4. pdflatex to *.pdf (pdflatex mwe.tex)

render() loses my -shell-escape option between steps 3 and 4, and I get an error since pdflatex cannot pass a command to the shell. Is there a way to either: 1) have pandoc output a *.pdf file instead of *.tex, or 2) pass -shell-escape onto pdflatex?

MWE: mwe.Rmd

title: "mwe"
header-includes: |
  \epstopdfDeclareGraphicsRule{.tif}{png}{.png}{sips -s format png #1 --out \OutputFile}
  \PrependGraphicsExtensions{.tif, .tiff}
    pandoc_args: "--pdf-engine-opt=-shell-escape"


Running $ rmarkdown::render("mwe.Rmd", output_file="mwe.pdf") in R console gives the error since pdflatex was not called with -shell-escape:

! Package pdftex.def Error: File `image-tif-converted-to.png' not found.

Error: Failed to compile mwe.tex. See mwe.log for more info.

Running $ knitr::knit("mwe.Rmd") in R console followed by $ pandoc -o mwe.pdf in the terminal returns the correct PDF. Alternatively, running $ pandoc -s -o mwe.tex; pdflatex -shell-escape mwe.tex on the intermediate tex file in the terminal also returns the correct PDF.

TIF image obtained from:


I too have now run into this problem, where I would like to include some TIFF files and have them auto-converted to PNG files. When I try typesetting the provided 'mwe.Rmd' from within the latest version of RStudio on a MacBook Air, it dies:

! Package pdftex.def Error: File `image-tif-converted-to.png' not found: using 
draft setting.

Error: Failed to compile mwe.tex. See mwe.log for more info.
Execution halted

Note that I changed the line to:

    pandoc_args: "--latex-engine-opt=-shell-escape"

and it looks like it is generating a pandoc command that contains the requested 'latex-engine-opt' option:

/Applications/ +RTS -K512m -RTS --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output mwe.tex --template /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rmarkdown/rmd/latex/default- --highlight-style tango --latex-engine pdflatex --variable graphics=yes --latex-engine-opt=-shell-escape --variable 'geometry:margin=1in' 

But the mwe.log indicates that the 'sips' command was not executed, and so the needed png file was not created:

runsystem(sips -s format png image.tif --out image-tif-converted-to.png)...disabled (restricted).

Would be nice to have a solution to this.

Thank you.