【发布时间】:2025-12-23 08:50:12
【问题描述】:
我在 RStudio 中使用 knitr,我正在寻找从 rmarkdown 文件创建文档时出现奇怪错误的解释。例如,我有一个文件 pdf-test.Rmd:
---
title: "PDF knit error"
output: pdf_document
---
##Headers
> ###Quote 1
This results in an error; if the blockquote symbol ('>') in
preceeding line is removed, no error
> ###Quote 2
This line is fine
当我尝试使用 Knit PDF 按钮创建 pdf 时,输出如下:
|……………………………………………………………………………………………………………………………… .............| 100% 没有R代码的普通文本 处理文件:pdf-test.Rmd 输出文件:pdf-test.knit.md /usr/bin/pandoc +RTS -K512m -RTS pdf-test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output pdf-test.pdf --template /home/jcoliver/R /x86_64-pc-linux-gnu-library/3.3/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable 'geometry:边距=1英寸 ! LaTeX 错误:出了点问题——可能是缺少 \item。 有关说明,请参阅 LaTeX 手册或 LaTeX Companion。 键入 H 以获得即时帮助。 ... l.94 \end{报价} pandoc:生成 PDF 时出错 错误:pandoc 文档转换失败,错误 43 执行停止如上所述,从第一个实例中删除块引号字符 (>) 会使错误消失(尽管所需的格式也是如此)。
---
title: "PDF knit error"
output: pdf_document
---
##Headers
###Quote 1
No error here
> ###Quote 2
This line remains fine
并且没有来自 pandoc/LaTeX 的投诉:
|……………………………………………………………………………………………………………………………… .............| 100% 没有R代码的普通文本 /usr/bin/pandoc +RTS -K512m -RTS pdf-test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output pdf-test.pdf --template /home/jcoliver/R /x86_64-pc-linux-gnu-library/3.3/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable 'geometry:边距=1英寸 处理文件:pdf-test.Rmd 输出文件:pdf-test.knit.md 创建的输出:pdf-test.pdf我也可以通过将块引用的标题级别更改为H4或更高(H5,H6等)来避免错误,而将第一个块引用的标题级别更改为H1或H2仍然会导致错误.
那么为什么会出现这个错误呢?为什么我不能在标题之后立即使用 H3 的块引用?请注意,我在标题行尝试了不同的标题级别(#Headers、##Headers、###Headers)、##Headers 行之后的不同间距以及不同的输出格式(即 HTML),但错误总是发生.
一些系统细节:
- Ubuntu 16.04
- pandoc 1.17.2(1.16.0.2 也出现错误)
- R 3.3.1
- RStudio 0.99.489
【问题讨论】:
标签: r latex rstudio knitr pandoc