diff options
author | John MacFarlane <jgm@berkeley.edu> | 2014-04-04 17:39:56 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2014-04-04 17:39:56 -0700 |
commit | 98658b55fc922d9ad3d883bdc3bdaddd2318dff2 (patch) | |
tree | 9c0084e5fc90d5a117885a07fb0575b08e3b7e0d /src/Text/Pandoc | |
parent | 6ceb2e26dcc542a8cf38e2e719348e848f354ac3 (diff) | |
download | pandoc-98658b55fc922d9ad3d883bdc3bdaddd2318dff2.tar.gz |
LaTeX writer: handle line breaks in simple table cells.
Closes #1217.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 07be6e9af..6cf7ed730 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -500,9 +500,28 @@ tableRowToLaTeX header aligns widths cols = do cells <- mapM (tableCellToLaTeX header) $ zip3 widths' aligns cols return $ hsep (intersperse "&" cells) $$ "\\\\\\addlinespace" +-- For simple latex tables (without minipages or parboxes), +-- we need to go to some lengths to get line breaks working: +-- as LineBreak bs = \vtop{\hbox{\strut as}\hbox{\strut bs}}. +fixLineBreaks :: Block -> Block +fixLineBreaks (Para ils) = Para $ fixLineBreaks' ils +fixLineBreaks (Plain ils) = Plain $ fixLineBreaks' ils +fixLineBreaks x = x + +fixLineBreaks' :: [Inline] -> [Inline] +fixLineBreaks' ils = case splitBy (== LineBreak) ils of + [] -> [] + [xs] -> xs + chunks -> RawInline "tex" "\\vtop{" : + concatMap tohbox chunks ++ + [RawInline "tex" "}"] + where tohbox ys = RawInline "tex" "\\hbox{\\strut " : ys ++ + [RawInline "tex" "}"] + tableCellToLaTeX :: Bool -> (Double, Alignment, [Block]) -> State WriterState Doc -tableCellToLaTeX _ (0, _, blocks) = blockListToLaTeX blocks +tableCellToLaTeX _ (0, _, blocks) = + blockListToLaTeX $ walk fixLineBreaks blocks tableCellToLaTeX header (width, align, blocks) = do modify $ \st -> st{ stInMinipage = True, stNotes = [] } cellContents <- blockListToLaTeX blocks |