git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: Put `~` before header in item text.

Because of the built-in line skip, LaTeX can't handle a section header as the first element in a list item. (To be precise, it can't handle it if the list immediately follows a section header, but the instance is rare enough that we can afford to be a bit more general). This puts a non-breaking space before the header to solve this problem. We won't see this space, since the header skips a line before printing anyway. The output is ugly in LaTeX and this structure seems like it should probably be avoided. But it is valid HTML and native pandoc, so we should have some sort of typesettable representation in LaTeX.

commitd3053807a834db7df115999fbcc4839e94e5f245 authorJesse Rosenthal <jrosenthal@jhu.edu> dateSun 31 Aug 2014, 15:44 (12 years ago) parent4455905
1 file changed+12−2
src/Text/Pandoc/Writers/LaTeX.hs+12−2
src/Text/Pandoc/Writers/LaTeX.hs+12−2
@@ -572,7 +572,13 @@ tableCellToLaTeX header (width, align, blocks) = do
572572 $ reverse ns)
573573
574574listItemToLaTeX :: [Block] -> State WriterState Doc
575−listItemToLaTeX lst = blockListToLaTeX lst >>= return . (text "\\item" $$) .
575+listItemToLaTeX lst
576+ -- we need to put some text before a header if it's the first
577+ -- element in an item. This will look ugly in LaTeX regardless, but
578+ -- this will keep the typesetter from throwing an error.
579+ | ((Header _ _ _) :_) <- lst =
580+ blockListToLaTeX lst >>= return . (text "\\item ~" $$) . (nest 2)
581+ | otherwise = blockListToLaTeX lst >>= return . (text "\\item" $$) .
576582 (nest 2)
577583
578584defListItemToLaTeX :: ([Inline], [[Block]]) -> State WriterState Doc
@@ -586,7 +592,11 @@ defListItemToLaTeX (term, defs) = do
586592 then braces term'
587593 else term'
588594 def' <- liftM vsep $ mapM blockListToLaTeX defs
589− return $ "\\item" <> brackets term'' $$ def'
595+ return $ case defs of
596+ (((Header _ _ _) : _) : _) ->
597+ "\\item" <> brackets term'' <> " ~ " $$ def'
598+ _ ->
599+ "\\item" <> brackets term'' $$ def'
590600
591601-- | Craft the section header, inserting the secton reference, if supplied.
592602sectionHeader :: Bool -- True for unnumbered