git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: Workaround for level 4-5 headers in quotes.

These previously produced invalid LaTeX: `\paragraph` or `\subparagraph` in a `quote` environment. This adds an `mbox{}` in these contexts to work around the problem. See http://tex.stackexchange.com/a/169833/22451. Closes #1221.

commite352ec5a0e4af245584972e89ae13352e907cdf0 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSun 6 Apr 2014, 16:32 (13 years ago) parentfcddd0e
1 file changed+14−2
src/Text/Pandoc/Writers/LaTeX.hs+14−2
src/Text/Pandoc/Writers/LaTeX.hs+14−2
@@ -51,6 +51,7 @@ import Text.Pandoc.Highlighting (highlight, styleToLaTeX,
5151
5252data WriterState =
5353 WriterState { stInNote :: Bool -- true if we're in a note
54+ , stInQuote :: Bool -- true if in a blockquote
5455 , stInMinipage :: Bool -- true if in minipage
5556 , stNotes :: [Doc] -- notes in a minipage
5657 , stOLLevel :: Int -- level of ordered list nesting
@@ -73,7 +74,8 @@ data WriterState =
7374writeLaTeX :: WriterOptions -> Pandoc -> String
7475writeLaTeX options document =
7576 evalState (pandocToLaTeX options document) $
76− WriterState { stInNote = False, stInMinipage = False, stNotes = [],
77+ WriterState { stInNote = False, stInQuote = False,
78+ stInMinipage = False, stNotes = [],
7779 stOLLevel = 1, stOptions = options,
7880 stVerbInNote = False,
7981 stTable = False, stStrikeout = False,
@@ -331,7 +333,10 @@ blockToLaTeX (BlockQuote lst) = do
331333 modify $ \s -> s{ stIncremental = oldIncremental }
332334 return result
333335 _ -> do
336+ oldInQuote <- gets stInQuote
337+ modify (\s -> s{stInQuote = True})
334338 contents <- blockListToLaTeX lst
339+ modify (\s -> s{stInQuote = oldInQuote})
335340 return $ "\\begin{quote}" $$ contents $$ "\\end{quote}"
336341blockToLaTeX (CodeBlock (identifier,classes,keyvalAttr) str) = do
337342 opts <- gets stOptions
@@ -610,9 +615,16 @@ sectionHeader unnumbered ref level lst = do
610615 4 -> "paragraph"
611616 5 -> "subparagraph"
612617 _ -> ""
618+ inQuote <- gets stInQuote
619+ let prefix = if inQuote && level' >= 4
620+ then text "\\mbox{}%"
621+ -- needed for \paragraph, \subparagraph in quote environment
622+ -- see http://tex.stackexchange.com/questions/169830/
623+ else empty
613624 return $ if level' > 5
614625 then txt
615− else headerWith ('\\':sectionType) stuffing ref
626+ else prefix $$
627+ headerWith ('\\':sectionType) stuffing ref
616628 $$ if unnumbered
617629 then "\\addcontentsline{toc}" <>
618630 braces (text sectionType) <>