git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: More consistent interblock spacing.
commit4e35c67c23875dc76a9a1409597b4c40f7834a70 authorJohn MacFarlane <fiddlosopher@gmail.com> dateMon 14 May 2012, 07:04 (14 years ago) parent4285954
5 files changed+35−30
src/Text/Pandoc/Writers/LaTeX.hs+18−24 tests/lhs-test.latex+1 tests/lhs-test.latex+lhs+1 tests/tables.latex−1 tests/writer.latex+15−5
src/Text/Pandoc/Writers/LaTeX.hs+18−24
@@ -117,7 +117,7 @@ pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
117117 else return blocks'
118118 body <- mapM (elementToLaTeX options) $ hierarchicalize blocks''
119119 biblioTitle <- liftM (render colwidth) $ inlineListToLaTeX lastHeader
120− let main = render colwidth $ vcat body
120+ let main = render colwidth $ vsep body
121121 st <- get
122122 let biblioFiles = intercalate "," $ map dropExtension $ writerBiblioFiles options
123123 citecontext = case writerCiteMethod options of
@@ -170,7 +170,7 @@ elementToLaTeX _ (Blk block) = blockToLaTeX block
170170elementToLaTeX opts (Sec level _ id' title' elements) = do
171171 header' <- sectionHeader id' level title'
172172 innerContents <- mapM (elementToLaTeX opts) elements
173− return $ vcat (header' : innerContents)
173+ return $ vsep (header' : innerContents)
174174
175175-- escape things as needed for LaTeX
176176stringToLaTeX :: Bool -> String -> State WriterState String
@@ -265,10 +265,10 @@ blockToLaTeX (Para [Image txt (src,tit)]) = do
265265 capt <- inlineListToLaTeX txt
266266 img <- inlineToLaTeX (Image txt (src,tit))
267267 return $ "\\begin{figure}[htbp]" $$ "\\centering" $$ img $$
268− ("\\caption{" <> capt <> char '}') $$ "\\end{figure}" $$ blankline
268+ ("\\caption{" <> capt <> char '}') $$ "\\end{figure}"
269269blockToLaTeX (Para lst) = do
270270 result <- inlineListToLaTeX lst
271− return $ result <> blankline
271+ return result
272272blockToLaTeX (BlockQuote lst) = do
273273 beamer <- writerBeamer `fmap` gets stOptions
274274 case lst of
@@ -280,8 +280,7 @@ blockToLaTeX (BlockQuote lst) = do
280280 return result
281281 _ -> do
282282 contents <- blockListToLaTeX lst
283− return $ "\\begin{quote}" $$ chomp contents $$ "\\end{quote}"
284− <> blankline
283+ return $ "\\begin{quote}" $$ contents $$ "\\end{quote}"
285284blockToLaTeX (CodeBlock (_,classes,keyvalAttr) str) = do
286285 opts <- gets stOptions
287286 case () of
@@ -300,11 +299,7 @@ blockToLaTeX (CodeBlock (_,classes,keyvalAttr) str) = do
300299 return "Verbatim"
301300 else return "verbatim"
302301 return $ flush (text ("\\begin{" ++ env ++ "}") $$ text str $$
303− text ("\\end{" ++ env ++ "}")) <> text "\n" <> blankline
304− -- note: we use 'text "\n"' instead of cr to make this
305− -- resistant to the 'chomp' in footnotes; a footnote
306− -- ending with a Verbatim environment must have a
307− -- cr before the closing }
302+ text ("\\end{" ++ env ++ "}")) <> cr
308303 listingsCodeBlock = do
309304 st <- get
310305 let params = if writerListings (stOptions st)
@@ -339,14 +334,14 @@ blockToLaTeX (CodeBlock (_,classes,keyvalAttr) str) = do
339334 Nothing -> rawCodeBlock
340335 Just h -> modify (\st -> st{ stHighlighting = True }) >>
341336 return (flush $ text h)
342−blockToLaTeX (RawBlock "latex" x) = return $ text x <> blankline
337+blockToLaTeX (RawBlock "latex" x) = return $ text x
343338blockToLaTeX (RawBlock _ _) = return empty
344339blockToLaTeX (BulletList lst) = do
345340 incremental <- gets stIncremental
346341 let inc = if incremental then "[<+->]" else ""
347342 items <- mapM listItemToLaTeX lst
348− return $ text ("\\begin{itemize}" ++ inc) $$ chomp (vcat items) $$
349− "\\end{itemize}" <> blankline
343+ return $ text ("\\begin{itemize}" ++ inc) $$ vcat items $$
344+ "\\end{itemize}"
350345blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
351346 st <- get
352347 let inc = if stIncremental st then "[<+->]" else ""
@@ -367,15 +362,15 @@ blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
367362 "}{" ++ show (start - 1) ++ "}"
368363 else empty
369364 return $ text ("\\begin{enumerate}" ++ inc) <> exemplar $$ resetcounter $$
370− chomp (vcat items) $$ "\\end{enumerate}" <> blankline
365+ vcat items $$ "\\end{enumerate}"
371366blockToLaTeX (DefinitionList lst) = do
372367 incremental <- gets stIncremental
373368 let inc = if incremental then "[<+->]" else ""
374369 items <- mapM defListItemToLaTeX lst
375− return $ text ("\\begin{description}" ++ inc) $$ chomp (vcat items) $$
376− "\\end{description}" <> blankline
370+ return $ text ("\\begin{description}" ++ inc) $$ vcat items $$
371+ "\\end{description}"
377372blockToLaTeX HorizontalRule = return $
378− "\\begin{center}\\rule{3in}{0.4pt}\\end{center}" $$ blankline
373+ "\\begin{center}\\rule{3in}{0.4pt}\\end{center}"
379374blockToLaTeX (Header level lst) = sectionHeader "" level lst
380375blockToLaTeX (Table caption aligns widths heads rows) = do
381376 modify $ \s -> s{ stInTable = True, stTableNotes = [] }
@@ -401,7 +396,7 @@ blockToLaTeX (Table caption aligns widths heads rows) = do
401396 $$ braces (text "% rows" $$ "\\FL" $$
402397 vcat (headers : rows'') $$ "\\LL" <> cr)
403398 modify $ \s -> s{ stTable = True, stInTable = False, stTableNotes = [] }
404− return $ tableBody $$ blankline
399+ return $ tableBody
405400
406401toColDescriptor :: Alignment -> String
407402toColDescriptor align =
@@ -412,7 +407,7 @@ toColDescriptor align =
412407 AlignDefault -> "l"
413408
414409blockListToLaTeX :: [Block] -> State WriterState Doc
415−blockListToLaTeX lst = mapM blockToLaTeX lst >>= return . vcat
410+blockListToLaTeX lst = vsep `fmap` mapM blockToLaTeX lst
416411
417412tableRowToLaTeX :: Bool
418413 -> [Alignment]
@@ -430,7 +425,7 @@ tableRowToLaTeX header aligns widths cols = do
430425 let toCell 0 _ c = c
431426 toCell w a c = "\\parbox" <> valign <>
432427 braces (text (printf "%.2f\\columnwidth" w)) <>
433− braces (halign a <> cr <> chomp c <> cr)
428+ braces (halign a <> cr <> c <> cr)
434429 let cells = zipWith3 toCell widths aligns renderedCells
435430 return $ hcat $ intersperse (" & ") cells
436431
@@ -473,7 +468,6 @@ sectionHeader ref level lst = do
473468 <> braces (lab <> text "\\label"
474469 <> braces (text ref))
475470 else lab)
476− $$ blankline
477471 let headerWith x y = refLabel $ text x <> y
478472 return $ case level' of
479473 0 -> if writerBeamer opts
@@ -484,7 +478,7 @@ sectionHeader ref level lst = do
484478 3 -> headerWith "\\subsubsection" stuffing
485479 4 -> headerWith "\\paragraph" stuffing
486480 5 -> headerWith "\\subparagraph" stuffing
487− _ -> txt $$ blankline
481+ _ -> txt
488482
489483
490484-- | Convert list of inline elements to LaTeX.
@@ -600,7 +594,7 @@ inlineToLaTeX (Note contents) = do
600594 let marker = cycle ['a'..'z'] !! length curnotes
601595 modify $ \s -> s{ stTableNotes = (marker, contents') : curnotes }
602596 return $ "\\tmark" <> brackets (char marker) <> space
603− else return $ "\\footnote" <> braces (chomp $ nest 2 contents')
597+ else return $ "\\footnote" <> braces (nest 2 contents')
604598 -- note: a \n before } needed when note ends with a Verbatim environment
605599
606600citationsToNatbib :: [Citation] -> State WriterState Doc
tests/lhs-test.latex+1
@@ -75,6 +75,7 @@ return a single value:
7575 \CommentTok{-- arr (\textbackslash{}op (x,y) -> x `op` y) }
7676\end{Highlighting}
7777\end{Shaded}
78+
7879\texttt{(***)} combines two arrows into a new arrow by running the two arrows
7980on a pair of values (one arrow on the first item of the pair and one arrow on
8081the second item of the pair).
tests/lhs-test.latex+lhs+1
@@ -55,6 +55,7 @@ unsplit :: (Arrow a) => (b -> c -> d) -> a (b, c) d
5555unsplit = arr . uncurry
5656 -- arr (\op (x,y) -> x `op` y)
5757\end{code}
58+
5859\texttt{(***)} combines two arrows into a new arrow by running the two arrows
5960on a pair of values (one arrow on the first item of the pair and one arrow on
6061the second item of the pair).
tests/tables.latex−1
@@ -173,4 +173,3 @@ Here's another one. Note the blank line between rows.
173173}
174174\LL
175175}
176−
tests/writer.latex+15−5
@@ -314,9 +314,11 @@ Multiple paragraphs:
314314\begin{itemize}
315315\item
316316 Tab
317+
317318 \begin{itemize}
318319 \item
319320 Tab
321+
320322 \begin{itemize}
321323 \item
322324 Tab
@@ -331,6 +333,7 @@ Here's another:
331333 First
332334\item
333335 Second:
336+
334337 \begin{itemize}
335338 \item
336339 Fee
@@ -396,6 +399,7 @@ Same thing but with paragraphs:
396399 sublist with roman numerals, starting with 4
397400 \item
398401 more items
402+
399403 \begin{enumerate}[(A)]
400404 \item
401405 a subsublist
@@ -410,13 +414,16 @@ Nesting:
410414\begin{enumerate}[A.]
411415\item
412416 Upper Alpha
417+
413418 \begin{enumerate}[I.]
414419 \item
415420 Upper Roman.
421+
416422 \begin{enumerate}[(1)]
417423 \setcounter{enumiii}{5}
418424 \item
419425 Decimal start with 6
426+
420427 \begin{enumerate}[a)]
421428 \setcounter{enumiv}{2}
422429 \item
@@ -433,6 +440,7 @@ Autonumbering:
433440 Autonumber.
434441\item
435442 More.
443+
436444 \begin{enumerate}
437445 \item
438446 Nested.
@@ -476,10 +484,8 @@ Loose:
476484\begin{description}
477485\item[apple]
478486red fruit
479−
480487\item[orange]
481488orange fruit
482−
483489\item[banana]
484490yellow fruit
485491\end{description}
@@ -491,7 +497,6 @@ Multiple blocks with italics:
491497red fruit
492498
493499contains seeds, crisp, pleasant to taste
494−
495500\item[\emph{orange}]
496501orange fruit
497502
@@ -524,7 +529,6 @@ Multiple definitions, loose:
524529red fruit
525530
526531computer
527−
528532\item[orange]
529533orange fruit
530534
@@ -538,7 +542,6 @@ Blank line after term, indented marker, alternate markers:
538542red fruit
539543
540544computer
541−
542545\item[orange]
543546orange fruit
544547
@@ -555,17 +558,23 @@ orange fruit
555558Simple block on one line:
556559
557560foo
561+
558562And nested without indentation:
559563
560564foo
565+
561566bar
567+
562568Interpreted markdown in a table:
563569
564570This is \emph{emphasized}
571+
565572And this is \textbf{strong}
573+
566574Here's a simple block:
567575
568576foo
577+
569578This should be a code block, though:
570579
571580\begin{verbatim}
@@ -583,6 +592,7 @@ As should this:
583592Now, nested:
584593
585594foo
595+
586596This should just be an HTML comment:
587597
588598Multiline: