无法编译带有外部 tikz 文件的 Rmd 文件

我正在尝试从一个带有一些 tikz 图形的 Rmd 文档来编译一个 pdf 文件。

Rmd 示例:

---
output:
  pdf_document:
    latex_engine: lualatex
header-includes:
    - \usepackage{tikz}
---

# Introduction

你好。

```{tikz img-plot, echo = FALSE, engine = "tikz", fig.ext = "pdf", fig.cap = "这是我的图片", code = readLines("testimg.tex")}
```

 \@ref(fig:img-plot) 无法正常工作。

参考的 tikz 文件 testimg.tex:

\begin{tikzpicture}
    \node at (0.5, 0.5) {(a)};
\end{tikzpicture}

使用以下命令在 R 中编译 Rmd 文件

$ echo "rmarkdown::render('test.Rmd', output_file='test.pdf')" | R --no-save -q

给我以下日志:

rmarkdown::render('test.Rmd', output_file='test.pdf')

处理文件: test.Rmd

|

|

| 0% |

|.......................

| 33% 普通文本无 R 代码

|

|...............................................

| 67% 标签: img-plot (with options) List of 5 $ echo : logi FALSE $ engine : chr "tikz" $ fig.ext: chr "pdf" $ fig.cap: chr "这是我的图片" $ code : language readLines("testimg.tex")

|

|......................................................................| 100% 普通文本无 R 代码

输出文件: test.knit.md

/usr/bin/pandoc +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output test.tex --template /usr/lib/R/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --pdf-engine lualatex --variable graphics=yes --lua-filter /usr/lib/R/library/rmarkdown/rmd/lua/pagebreak.lua --lua-filter /usr/lib/R/library/rmarkdown/rmd/lua/latex-div.lua --variable 'geometry:margin=1in' --variable 'compact-title:yes' ! error: (file "test_files/figure-latex/""img-plot-1".pdf) (pdf backend): canno

错误: 无法编译 test.tex。参见 https://yihui.name/tinytex/r/#debugging 以进行调试。参见 test.log 以获取更多信息。执行已停止

错误日志显示 ""img-plot-1".pdf 中有一个双引号。这可能与它有关吗?

我曾经可以编译一个类似的文件,几周前,这就是为什么我猜测一些更新在 R 包、pandoc 或其他地方的系统中损坏了它。任何关于这个问题的想法?

系统信息:

  • 操作系统: Linux Kernel 4.19.85-1-MANJARO
  • R 3.6.1
  • rmarkdown 包: 1.17
  • pandoc 2.7.3
点赞