git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: handle line breaks in simple table cells.

Closes #1217.

commit98658b55fc922d9ad3d883bdc3bdaddd2318dff2 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 4 Apr 2014, 17:39 (13 years ago) parent6ceb2e2
1 file changed+20−1
src/Text/Pandoc/Writers/LaTeX.hs+20−1
src/Text/Pandoc/Writers/LaTeX.hs+20−1
@@ -500,9 +500,28 @@ tableRowToLaTeX header aligns widths cols = do
500500 cells <- mapM (tableCellToLaTeX header) $ zip3 widths' aligns cols
501501 return $ hsep (intersperse "&" cells) $$ "\\\\\\addlinespace"
502502
503+-- For simple latex tables (without minipages or parboxes),
504+-- we need to go to some lengths to get line breaks working:
505+-- as LineBreak bs = \vtop{\hbox{\strut as}\hbox{\strut bs}}.
506+fixLineBreaks :: Block -> Block
507+fixLineBreaks (Para ils) = Para $ fixLineBreaks' ils
508+fixLineBreaks (Plain ils) = Plain $ fixLineBreaks' ils
509+fixLineBreaks x = x
510+
511+fixLineBreaks' :: [Inline] -> [Inline]
512+fixLineBreaks' ils = case splitBy (== LineBreak) ils of
513+ [] -> []
514+ [xs] -> xs
515+ chunks -> RawInline "tex" "\\vtop{" :
516+ concatMap tohbox chunks ++
517+ [RawInline "tex" "}"]
518+ where tohbox ys = RawInline "tex" "\\hbox{\\strut " : ys ++
519+ [RawInline "tex" "}"]
520+
503521tableCellToLaTeX :: Bool -> (Double, Alignment, [Block])
504522 -> State WriterState Doc
505−tableCellToLaTeX _ (0, _, blocks) = blockListToLaTeX blocks
523+tableCellToLaTeX _ (0, _, blocks) =
524+ blockListToLaTeX $ walk fixLineBreaks blocks
506525tableCellToLaTeX header (width, align, blocks) = do
507526 modify $ \st -> st{ stInMinipage = True, stNotes = [] }
508527 cellContents <- blockListToLaTeX blocks