What causes a pandoc document conversion error when blockquote follows header

I am using knitr in RStudio and I am looking for an explanation for an odd error when creating a document from an rmarkdown file. As in example, I have a file, 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

When I try to create a pdf using the Knit PDF button, this is the output:

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

As mentioned above, removing the block quote character ( > ) from the first instance makes the error go away (although so does the desired formatting).

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

##Headers

###Quote 1
No error here

> ###Quote 2
This line remains fine

And there are no complaints from 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

I can also avoid the error by changing the header level of the block quote to H4 or higher (H5, H6, etc.), while changing the header level of the first block quote to H1 or H2 still results in an error.

So why is this error occurring? Why can I not have a block quote with H3 immediately following a header? Note that I have tried different header levels on the header line( #Headers , ##Headers , ###Headers ), varying spacing following the ##Headers line, and a different output format (ie HTML), but the error always occurred.

A few system details:

  • Ubuntu 16.04
  • pandoc 1.17.2 (error also occurred with 1.16.0.2)
  • R 3.3.1
  • RStudio 0.99.489

  • You want to quote a section header, directly after a section header? This sounds indeed special and it looks like pandoc cannot handle this.

    As proposed in eipi10's answer, a solution is to add something between the header and the quote. However, I think you should not add white filler text to the document. For example, when you copy text from the PDF, the filler becomes visible.

    Instead, just add an (empty) box: mbox{} . Then, to avoid excessive vertical whitespace due to the extra line we introduced, add some negative vertical space: vspace*{-1cm} .

    ---
    output: pdf_document
    ---
    
    ##Headers
    
    mbox{}vspace*{-1cm}
    
    > ### Quoted Section
    
    Foobar.
    


    I'm not sure why the error is occurring, but here's a hack that allows you to have the H3 header in block quotes immediately after the H2 header, with no intervening text.

    The basic idea is that you do add some text between the headers, but you set its color to white (you'll also need to declare usepackage{color} in the header for this to work). Then, because that also adds too much space between the headers, you make the text really small using tiny and reduce the space between lines with vspace*{-baselineskip} . (I originally tried adding phantom text using phantom{aaa} , but that still resulted in the same error, so I switched to "real" text, but rendered in the same color as the background (ie, white).)

    ---
    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
    

    在这里输入图像描述

    链接地址: http://www.djcxy.com/p/33474.html

    上一篇: RMarkdown / pandoc无法用乳胶颜色命令编织PDF

    下一篇: 当blockquote跟在标题后面时,会导致pandoc文档转换错误