git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: Factored out function for table cell creation.
commita3f6f2827c9acb0e68ac533745b3f4dc8836ee24 authorJohn MacFarlane <fiddlosopher@gmail.com> dateTue 17 Dec 2013, 20:10 (13 years ago) parent0132f6f
1 file changed+17−13
src/Text/Pandoc/Writers/LaTeX.hs+17−13
src/Text/Pandoc/Writers/LaTeX.hs+17−13
@@ -490,24 +490,28 @@ tableRowToLaTeX :: Bool
490490 -> [[Block]]
491491 -> State WriterState Doc
492492tableRowToLaTeX header aligns widths cols = do
493− renderedCells <- mapM blockListToLaTeX cols
494− let valign = text $ if header then "[b]" else "[t]"
495− let halign x = case x of
496− AlignLeft -> "\\raggedright"
497− AlignRight -> "\\raggedleft"
498− AlignCenter -> "\\centering"
499− AlignDefault -> "\\raggedright"
500493 -- scale factor compensates for extra space between columns
501494 -- so the whole table isn't larger than columnwidth
502495 let scaleFactor = 0.97 ** fromIntegral (length aligns)
503− let toCell 0 _ c = c
504− toCell w a c = "\\begin{minipage}" <> valign <>
505− braces (text (printf "%.2f\\columnwidth"
506− (w * scaleFactor))) <>
507− (halign a <> cr <> c <> cr) <> "\\end{minipage}"
508− let cells = zipWith3 toCell widths aligns renderedCells
496+ let widths' = map (scaleFactor *) widths
497+ cells <- mapM (tableCellToLaTeX header) $ zip3 widths' aligns cols
509498 return $ hsep (intersperse "&" cells) $$ "\\\\\\addlinespace"
510499
500+tableCellToLaTeX :: Bool -> (Double, Alignment, [Block])
501+ -> State WriterState Doc
502+tableCellToLaTeX _ (0, _, blocks) = blockListToLaTeX blocks
503+tableCellToLaTeX header (width, align, blocks) = do
504+ cellContents <- blockListToLaTeX blocks
505+ let valign = text $ if header then "[b]" else "[t]"
506+ let halign = case align of
507+ AlignLeft -> "\\raggedright"
508+ AlignRight -> "\\raggedleft"
509+ AlignCenter -> "\\centering"
510+ AlignDefault -> "\\raggedright"
511+ return $ "\\begin{minipage}" <> valign <>
512+ braces (text (printf "%.2f\\columnwidth" width)) <>
513+ (halign <> cr <> cellContents <> cr) <> "\\end{minipage}"
514+
511515listItemToLaTeX :: [Block] -> State WriterState Doc
512516listItemToLaTeX lst = blockListToLaTeX lst >>= return . (text "\\item" $$) .
513517 (nest 2)