当 blockquote 跟随 header 时,是什么导致 pandoc 文档转换错误

What causes a pandoc document conversion error when blockquote follows header

我在 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%
  ordinary text without R code

processing file: pdf-test.Rmd
output file: 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:margin=1in' 
! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H   for immediate help.
 ...                                              

l.94 \end{quote}

pandoc: Error producing PDF
Error: pandoc document conversion failed with error 43
Execution halted

如上所述,从第一个实例中删除块引号字符 (>) 会使错误消失(尽管所需的格式也是如此)。

---
title: "PDF knit error"
output: pdf_document
---

##Headers

###Quote 1
No error here

> ###Quote 2
This line remains fine

pandoc/LaTeX没有投诉:

  |.................................................................| 100%
  ordinary text without R code

/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:margin=1in' 

processing file: pdf-test.Rmd
output file: pdf-test.knit.md

Output created: pdf-test.pdf

我也可以通过将块引用的header级别更改为H4或更高级别(H5,H6等)来避免错误,同时更改第一个块的header级别引用 H1 或 H2 仍然会导致错误。

那么为什么会出现这个错误呢?为什么我不能在 header 后立即使用 H3 块引用?请注意,我在 header 行(#Headers##Headers###Headers)上尝试了不同的 header 级别,在 ##Headers 行之后改变间距, 和不同的输出格式(即 HTML),但错误总是发生。

一些系统细节:

我不确定为什么会出现错误,但这里有一个 hack 允许您在 H2 header 之后立即在块引号中使用 H3 header,中间没有文本。

基本思路是 do 在 header 之间添加一些文本,但将其颜色设置为白色(您还需要声明 \usepackage{color} 在 header 中才能工作)。然后,因为这也在 header 之间添加了太多 space,所以使用 \tiny 使文本非常小,并使用 \vspace*{-\baselineskip} 减少行之间的 space . (我最初尝试使用 \phantom{aaa} 添加幻影文本,但仍然导致相同的错误,所以我切换到 "real" 文本,但呈现为与背景相同的颜色(即白色)。)

---
title: "PDF knit error"
output: 
  pdf_document:
    number_sections: no
header-includes:
  - \usepackage{color}
---

##Headers

\vspace*{-\baselineskip}
\tiny
\begin{itemize}
\color{white}
\item Some text  
\end{itemize}
\normalsize
\vspace*{-\baselineskip}

> ###Quote 1  
This results in an error; if the blockquote symbol ('>') in 
preceeding line is removed, no error

> ###Quote 2  
This line is fine

您想直接在 header 部分之后引用 header 部分吗?这听起来确实很特别,看起来 pandoc 无法处理这个问题。

eipi10's answer 中所提议,一个解决方案是在 header 和引号之间添加 something。但是,我认为您应该 在文档中添加白色填充文本。例如,当您从 PDF 复制文本时,填充符会变为可见。

相反,只需添加一个(空)框:\mbox{}。然后,为了避免由于我们引入的额外行导致过多的垂直白色space,添加一些负垂直space:\vspace*{-1cm}.

---
output: pdf_document
---

##Headers

\mbox{}\vspace*{-1cm}

> ### Quoted Section

Foobar.