From d3053807a834db7df115999fbcc4839e94e5f245 Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Sun, 31 Aug 2014 15:44:07 -0400 Subject: 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. --- src/Text/Pandoc/Writers/LaTeX.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index acbe8a48d..8e3befe19 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -572,7 +572,13 @@ tableCellToLaTeX header (width, align, blocks) = do $ reverse ns) listItemToLaTeX :: [Block] -> State WriterState Doc -listItemToLaTeX lst = blockListToLaTeX lst >>= return . (text "\\item" $$) . +listItemToLaTeX lst + -- we need to put some text before a header if it's the first + -- element in an item. This will look ugly in LaTeX regardless, but + -- this will keep the typesetter from throwing an error. + | ((Header _ _ _) :_) <- lst = + blockListToLaTeX lst >>= return . (text "\\item ~" $$) . (nest 2) + | otherwise = blockListToLaTeX lst >>= return . (text "\\item" $$) . (nest 2) defListItemToLaTeX :: ([Inline], [[Block]]) -> State WriterState Doc @@ -586,7 +592,11 @@ defListItemToLaTeX (term, defs) = do then braces term' else term' def' <- liftM vsep $ mapM blockListToLaTeX defs - return $ "\\item" <> brackets term'' $$ def' + return $ case defs of + (((Header _ _ _) : _) : _) -> + "\\item" <> brackets term'' <> " ~ " $$ def' + _ -> + "\\item" <> brackets term'' $$ def' -- | Craft the section header, inserting the secton reference, if supplied. sectionHeader :: Bool -- True for unnumbered -- cgit v1.2.3