-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Description
Description
Headers at levels 1-3 (H1, H2, H3) inside blockquotes generate invalid LaTeX that fails to compile. This appears to be an incomplete fix from issue #1221 (2014), which only addressed H4-H6 headers.
Note: Headers in blockquotes are valid CommonMark syntax (see CommonMark Spec v0.31.2, Example 228). Pandoc correctly parses this syntax but generates invalid LaTeX output.
Environment
- Pandoc version: 3.8.2.1
- LaTeX engine: XeTeX 3.141592653-2.6-0.999997 (TeX Live 2025)
- Operating system: macOS (Darwin 25.2.0)
Minimal Reproducible Example
Test Case 1: H1 in Blockquote (FAILS)
Input Markdown:
# Test Document
> # H1 Header in Blockquote
>
> This should work but fails to compile.Command:
pandoc test-h1.md -o test-h1.pdfGenerated LaTeX:
\begin{quote}
\section{H1 Header in Blockquote}\label{h1-header-in-blockquote}
This should work but fails to compile.
\end{quote}Error:
Error producing PDF.
! LaTeX Error: Something's wrong--perhaps a missing \item.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.60 \end{quote}
Test Case 2: H4 in Blockquote (WORKS)
Input Markdown:
# Test Document
> #### H4 Header in Blockquote
>
> This works correctly.Generated LaTeX:
\begin{quote}
\mbox{}%
\paragraph{H4 Header in Blockquote}\label{h4-header-in-blockquote}
This works correctly.
\end{quote}Result: ✅ Compiles successfully
Systematic Testing Results
I tested all header levels (H1-H6) inside blockquotes:
| Header Level | LaTeX Command | Inside \begin{quote} |
Result |
|---|---|---|---|
| H1 (#) | \section |
❌ Invalid LaTeX | FAILS |
| H2 (##) | \subsection |
❌ Invalid LaTeX | FAILS |
| H3 (###) | \subsubsection |
❌ Invalid LaTeX | FAILS |
| H4 (####) | \paragraph |
✅ Has \mbox{}% prefix |
WORKS |
| H5 (#####) | \subparagraph |
✅ Has \mbox{}% prefix |
WORKS |
| H6 (######) | \subparagraph |
✅ Has \mbox{}% prefix |
WORKS |
Root Cause
LaTeX's quote environment is a list-based environment. Sectioning commands like \section, \subsection, and \subsubsection cannot appear directly inside list environments without special handling.
The 2014 fix (commit e352ec5) added a \mbox{}% prefix for headers inside blockquotes, but only for level >= 4:
-- From src/Text/Pandoc/Writers/LaTeX.hs (commit e352ec5)
sectionHeader level inQuote title = do
let prefix = if inQuote && level >= 4 then "\\mbox{}%" else ""
prefix <> renderSection level titleThis condition level >= 4 left H1-H3 broken.
Historical Context
- Original issue: HTML -> LaTeX -[pdflatex]-> PDF fail due h4 or h5 inside blockquote #1221 (2014) - "Quotations cannot contain subsections"
- Fix commit: e352ec5 (2014) - Added
stInQuotestate tracking and\mbox{}%workaround - Problem: Fix only applied to
level >= 4(H4-H6), not H1-H3
Expected Behavior
All header levels (H1-H6) should compile successfully when placed inside blockquotes, just as H4-H6 currently do.
Proposed Solution
Extend the 2014 fix to apply to all header levels (1-6), not just levels 4-6:
-- Change from:
if inQuote && level >= 4 then "\\mbox{}%" else ""
-- To:
if inQuote then "\\mbox{}%" else ""Or, if there's a specific reason to exclude H1-H3, use a different workaround for those levels.
Workaround
For now, users can avoid this issue by:
- Using bold/italic text instead of headers inside blockquotes
- Restructuring content to avoid headers in blockquotes
- Using a custom Lua filter to add the
\mbox{}%prefix
Example workaround:
> **Header Text in Bold** (instead of > ## Header)Impact
Minor. Technically this affects any Markdown document with headers inside blockquotes, which can't be that common as nobody has complained since 2014.
How This Was Discovered
This bug was discovered while developing a Markdown-to-PDF conversion tool that supports both Chrome and LaTeX backends.
During testing with a standard Markdown test file (https://github.com/mxstbr/markdown-test-file) that exercises all standard Markdown features, we found that:
- The test file compiled successfully with Chrome/Chromium backend
- It failed with LaTeX backend due to
> ## Header in Blockquotesyntax - Systematic testing of all header levels (H1-H6) revealed the pattern: H1-H3 fail, H4-H6 work
- Research led to the 2014 issue HTML -> LaTeX -[pdflatex]-> PDF fail due h4 or h5 inside blockquote #1221 and analysis of commit e352ec5 showed the incomplete fix
The test file had to be modified (changing > ## Header to > **Header**) to work around this limitation.