YAML标头中的Latex Shell-Escape选项不使用

时间:2019-04-01 16:46:10

标签: r latex r-markdown pandoc

我正在撰写有关Rmarkdovn的报告,但是当您尝试编译时-编译pdf时会忽略pandoc_args选项。

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

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

编译命令:

Rscript -e "rmarkdown::render('test.rmd')"

test.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}
---

输出:

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

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

1 个答案:

答案 0 :(得分:0)

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

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

有关更多信息,请参见帮助页面?tinytex::latexmk

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