YAML 标头中的 Latex shell-escape 选项不使用

Ren*_*sat 3 latex r pandoc r-markdown

我正在写一份关于 Rmarkdovn 的报告,但是当你尝试编译时 - pandoc_args 选项在编译 pdf 时被忽略。

我发现这个问题: Is it possible to include svg image in pdf documentendered by rmarkdown?

但它不起作用,因为--latex-engine-opt--pdf-engine-opt替换。我更换了,但也没用。

编译命令:

Rscript -e "rmarkdown::render('test.rmd')"
Run Code Online (Sandbox Code Playgroud)

测试.rmd

---
title: Test
papersize: a4paper
output:
  pdf_document:
    latex_engine: pdflatex
    pandoc_args: [
      --pdf-engine-opt, -shell-escape,
      --pdf-engine-opt, -interaction=nonstopmode]
header-includes:
  - \usepackage{minted}
---
Run Code Online (Sandbox Code Playgroud)

输出:

processing file: test.rmd
  |................................                                 |  50%
  ordinary text without R code

  |.................................................................| 100%
label: unnamed-chunk-1 (with options)
List of 1
 $ engine: chr "python"


output file: test.knit.md

/usr/bin/pandoc +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.tex --template /home/renesat/R/x86_64-pc-linux-gnu-library/3.5/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --pdf-engine pdflatex --variable graphics=yes --pdf-engine-opt --shell-escape --pdf-engine-opt -interaction=nonstopmode --variable 'geometry:margin=1in' --variable 'compact-title:yes'
! Package minted Error: You must invoke LaTeX with the -shell-escape flag.

Error: Failed to compile test.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See test.log for more info.
Execution halted
Run Code Online (Sandbox Code Playgroud)

我可以使用 knit -> pandoc -> xelatex,但使用 YAML 标头会更方便。

Yih*_*Xie 6

R Markdown 文档通过 编译为 PDF tinytex::latexmk()。要为您的 LaTeX 引擎启用该-shell-escape选项,您可以设置全局选项tinytex.engine_args,例如,将此代码块添加到您的文档中:

```{r, include=FALSE}
options(tinytex.engine_args = '-shell-escape')
```
Run Code Online (Sandbox Code Playgroud)

请参阅帮助页面?tinytex::latexmk以获取更多信息。

LaTeX 引擎是由tinytex::latexmk()Pandoc 调用的,因此 Pandoc 参数--pdf-engine-opt不起作用。