I am writing a bookdown project using the LaTeX minted
package to do code formatting. The minted
package requires invoking pdflatex
with the -shell-escape
option.
See the related question Latex shell-escape options in YAML header don't use
I can do this in individual .Rmd
files by putting options(tinytex.engine_args = "-shell-escape")
in a startup chunk at the beginning of the document, but this doesn't seem to work when I invoke bookdown::render_book("Index.Rmd", output_format = "bookdown::pdf_book")
.
I have tried setting pandoc_args: "--pdf-engine-opt=-shell-escape"
in output settings the _bookdown.yml
file
output:
bookdown::pdf_book:
pandoc_args: "--pdf-engine-opt=-shell-escape"
but this doesn't work.
I can get the book to knit properly if I manually set options(tinytex.engine_args="-shell_escape")
from the R console before running bookdown::render_book
library(bookdown)
options(tinytex.engine_args="-shell-escape")
render_book("Index.Rmd", output_format = "bookdown::pdf_book")
but I am wondering whether there is a way to set the tinytex.engine_args
option programmatically from _bookdown.yml
or one of my .Rmd
files or something similar every time I run bookdown::render_book
.
Indeed, the relevant statement to be executed is:
options(tinytex.engine_args="-shell-escape")
The only solution to automate this seems to be including that line in an .Rprofile
config file, that should be located in the root directory of your RStudio project. Hence:
.Rprofile
in your project directory and insert the line of code mentioned above..Rprofile
.minted
). Now, the book should compile without errors.Other alternatives, like including the same line of code in a chunk inside the index.Rmd
file do not work.