rmarkdown::render() 不会将 -shell-escape 选项从 pandoc 传递给 pdflate



我想渲染一个 Rmarkdown 文件,该文件需要在 pdflatex 中使用-shell-escape选项或在 pandoc 中--pdf-engine-opt=-shell-escape选项。我在 YAML 标头中指定了pandoc_args: "--pdf-engine-opt=-shell-escape",但 rmarkdown::render(( 似乎按以下顺序调用程序:

  1. knitr::knit(( to *.md
  2. 编码转换为 *.utf8.md
  3. 潘多克至 *.tex (pandoc mwe.utf8.md --to latex --output mwe.tex ...(
  4. pdflatex to *.pdf (pdflatex mwe.tex(

render(( 在步骤 3 和 4 之间丢失了我的-shell-escape选项,并且我收到一个错误,因为 pdflatex 无法将命令传递给 shell。有没有办法:1(让pandoc输出一个*.pdf文件而不是*.tex,或者2(-shell-escape传递到pdflatex上?

MWE:mwe。马币

---
title: "mwe"
header-includes: |
usepackage{epstopdf}
epstopdfDeclareGraphicsRule{.tif}{png}{.png}{sips -s format png #1 --out OutputFile}
PrependGraphicsExtensions{.tif, .tiff}
output: 
pdf_document:
pandoc_args: "--pdf-engine-opt=-shell-escape"
---
![](image.tif)

在 R 控制台中运行$ rmarkdown::render("mwe.Rmd", output_file="mwe.pdf")会给出错误,因为 pdflatex 没有被-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.

在 R 控制台中运行$ knitr::knit("mwe.Rmd"),然后在终端中运行$ pandoc mwe.md -o mwe.pdf将返回正确的 PDF。或者,在终端中的中间 tex 文件上运行$ pandoc mwe.md -s -o mwe.tex; pdflatex -shell-escape mwe.tex也会返回正确的 PDF。

TIF图像来源:https://upload.wikimedia.org/wikipedia/commons/6/6a/Chi_Recombination_Model_for_Wikipedia.tif

我在尝试导入铸造的乳胶包时遇到了同样的问题 -.rmd文件开头附近的这个 R 代码为我修复了它:

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

如果相关,我正在使用 RStudio 和 sweave 在 MacOS 10.14.6 上编译文档。希望这有帮助!

最新更新