Skip to content

Commit 1d238e9

Browse files
committed
LaTeX writer: don't invariably insert blanks between blocks.
Plain or RawBlock elements should not automatically be followed by blank lines. See #7111
1 parent 5e92187 commit 1d238e9

4 files changed

Lines changed: 34 additions & 34 deletions

File tree

cabal.project

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ source-repository-package
2121
location: https://github.com/jgm/texmath.git
2222
tag: 2a40f5d26d9b888559fd573ea8e7cb9c0114f9ee
2323

24+
source-repository-package
25+
type: git
26+
location: https://github.com/jgm/doclayout.git
27+
tag: eeb53975379e40166e36aec0315cd933607f2aff
28+
2429
-- TODO: release new skylighting-core, skylighting

src/Text/Pandoc/Writers/LaTeX.hs

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,10 @@ blockToLaTeX (Div attr@(identifier,"block":dclasses,_)
357357
else (cr <>) <$> hypertarget identifier
358358
title' <- inlineListToLaTeX ils
359359
contents <- blockListToLaTeX bs
360-
wrapDiv attr $ ("\\begin" <> braces blockname <> braces title' <> anchor) $$
361-
contents $$ "\\end" <> braces blockname
360+
($$ blankline) <$> wrapDiv attr
361+
(("\\begin" <> braces blockname <> braces title' <> anchor) $$
362+
contents $$
363+
"\\end" <> braces blockname)
362364
blockToLaTeX (Div (identifier,"slide":dclasses,dkvs)
363365
(Header _ (_,hclasses,hkvs) ils : bs)) = do
364366
-- note: [fragile] is required or verbatim breaks
@@ -392,7 +394,7 @@ blockToLaTeX (Div (identifier,"slide":dclasses,dkvs)
392394
else (cr <>) <$> hypertarget identifier
393395
contents <- blockListToLaTeX bs >>= wrapDiv (identifier,classes,kvs)
394396
return $ ("\\begin{frame}" <> options <> slideTitle <> slideAnchor) $$
395-
contents $$ "\\end{frame}"
397+
contents $$ "\\end{frame}" $$ blankline
396398
blockToLaTeX (Div (identifier@(T.uncons -> Just (_,_)),dclasses,dkvs)
397399
(Header lvl ("",hclasses,hkvs) ils : bs)) =
398400
-- move identifier from div to header
@@ -433,23 +435,24 @@ blockToLaTeX (Div (identifier,classes,kvs) bs) = do
433435
| otherwise = do
434436
linkAnchor <- hypertarget identifier
435437
pure $ linkAnchor $$ txt
436-
wrapDiv (identifier,classes,kvs) result >>= wrap
438+
($$ blankline) <$> (wrapDiv (identifier,classes,kvs) result >>= wrap)
437439
blockToLaTeX (Plain lst) =
438440
inlineListToLaTeX lst
439-
-- . . . indicates pause in beamer slides
441+
-- . . . indicates pause in beamer slides
440442
blockToLaTeX (Para [Str ".",Space,Str ".",Space,Str "."]) = do
441443
beamer <- gets stBeamer
442444
if beamer
443445
then blockToLaTeX (RawBlock "latex" "\\pause")
444-
else inlineListToLaTeX [Str ".",Space,Str ".",Space,Str "."]
446+
else ($$ blankline) . (blankline $$)
447+
<$> inlineListToLaTeX [Str ".",Space,Str ".",Space,Str "."]
445448
blockToLaTeX (Para lst) =
446449
if null lst
447450
then do
448451
opts <- gets stOptions
449452
if isEnabled Ext_empty_paragraphs opts
450-
then pure "\\hfill\\par"
453+
then pure $ "\\hfill\\par" $$ blankline
451454
else pure mempty
452-
else inlineListToLaTeX lst
455+
else (blankline $$) . ($$ blankline) <$> inlineListToLaTeX lst
453456
blockToLaTeX (LineBlock lns) =
454457
blockToLaTeX $ linesToPara lns
455458
blockToLaTeX (BlockQuote lst) = do
@@ -470,7 +473,8 @@ blockToLaTeX (BlockQuote lst) = do
470473
let envname = if csquotes then "displayquote" else "quote"
471474
return $ ("\\begin" <> braces envname) $$
472475
contents $$
473-
("\\end" <> braces envname)
476+
("\\end" <> braces envname) $$
477+
blankline
474478
blockToLaTeX (CodeBlock (identifier,classes,keyvalAttr) str) = do
475479
opts <- gets stOptions
476480
inNote <- stInNote <$> get
@@ -527,7 +531,8 @@ blockToLaTeX (CodeBlock (identifier,classes,keyvalAttr) str) = do
527531
when inNote $ modify (\s -> s{ stVerbInNote = True })
528532
modify (\s -> s{ stHighlighting = True })
529533
return (flush $ linkAnchor $$ text (T.unpack h))
530-
case () of
534+
($$ blankline) <$>
535+
case () of
531536
_ | isEnabled Ext_literate_haskell opts && "haskell" `elem` classes &&
532537
"literate" `elem` classes -> lhsCodeBlock
533538
| writerListings opts -> listingsCodeBlock
@@ -564,7 +569,8 @@ blockToLaTeX (BulletList lst) = do
564569
spacing $$
565570
-- force list at beginning of definition to start on new line
566571
vcat items $$
567-
"\\end{itemize}"
572+
"\\end{itemize}" $$
573+
blankline
568574
blockToLaTeX (OrderedList _ []) = return empty -- otherwise latex error
569575
blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
570576
st <- get
@@ -618,6 +624,7 @@ blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
618624
$$ spacing
619625
$$ vcat items
620626
$$ "\\end{enumerate}"
627+
$$ blankline
621628
blockToLaTeX (DefinitionList []) = return empty
622629
blockToLaTeX (DefinitionList lst) = do
623630
incremental <- gets stIncremental
@@ -628,17 +635,18 @@ blockToLaTeX (DefinitionList lst) = do
628635
then text "\\tightlist"
629636
else empty
630637
return $ text ("\\begin{description}" <> inc) $$ spacing $$ vcat items $$
631-
"\\end{description}"
632-
blockToLaTeX HorizontalRule =
633-
return
634-
"\\begin{center}\\rule{0.5\\linewidth}{0.5pt}\\end{center}"
638+
"\\end{description}" $$
639+
blankline
640+
blockToLaTeX HorizontalRule = return $
641+
"\\begin{center}\\rule{0.5\\linewidth}{0.5pt}\\end{center}" $$ blankline
635642
blockToLaTeX (Header level (id',classes,_) lst) = do
636643
modify $ \s -> s{stInHeading = True}
637644
hdr <- sectionHeader classes id' level lst
638645
modify $ \s -> s{stInHeading = False}
639-
return hdr
646+
return $ hdr $$ blankline
640647
blockToLaTeX (Table attr blkCapt specs thead tbodies tfoot) =
641-
tableToLaTeX inlineListToLaTeX blockListToLaTeX
648+
($$ blankline) <$>
649+
tableToLaTeX inlineListToLaTeX blockListToLaTeX
642650
(Ann.toTable attr blkCapt specs thead tbodies tfoot)
643651
blockToLaTeX (Figure (ident, _, _) captnode body) = do
644652
opts <- gets stOptions
@@ -678,6 +686,7 @@ blockToLaTeX (Figure (ident, _, _) captnode body) = do
678686
innards
679687
_ -> cr <> "\\begin{figure}" $$ innards $$ "\\end{figure}")
680688
$$ footnotes
689+
$$ blankline
681690

682691
toSubfigure :: PandocMonad m => Int -> Block -> LW m (Doc Text)
683692
toSubfigure nsubfigs blk = do
@@ -696,8 +705,8 @@ toSubfigure nsubfigs blk = do
696705
]
697706

698707
blockListToLaTeX :: PandocMonad m => [Block] -> LW m (Doc Text)
699-
blockListToLaTeX lst =
700-
vsep `fmap` mapM (\b -> setEmptyLine True >> blockToLaTeX b) lst
708+
blockListToLaTeX lst = (nestle . chomp . vcat) <$>
709+
mapM (\b -> setEmptyLine True >> blockToLaTeX b) lst
701710

702711
listItemToLaTeX :: PandocMonad m => Bool -> [Block] -> LW m (Doc Text)
703712
listItemToLaTeX isOrdered lst
@@ -742,7 +751,7 @@ defListItemToLaTeX (term, defs) = do
742751
firstitem <- blockToLaTeX x
743752
modify $ \s -> s{stIsFirstInDefinition = False }
744753
rest <- blockListToLaTeX xs
745-
return $ firstitem $+$ rest
754+
return $ chomp . nestle $ firstitem $+$ rest
746755
return $ case defs of
747756
((Header{} : _) : _) ->
748757
"\\item" <> brackets term'' <> " ~ " $$ def'

test/writer.latex

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,10 @@ Multiple paragraphs:
339339
\tightlist
340340
\item
341341
Tab
342-
343342
\begin{itemize}
344343
\tightlist
345344
\item
346345
Tab
347-
348346
\begin{itemize}
349347
\tightlist
350348
\item
@@ -362,7 +360,6 @@ Here's another:
362360
First
363361
\item
364362
Second:
365-
366363
\begin{itemize}
367364
\tightlist
368365
\item
@@ -434,7 +431,6 @@ Same thing but with paragraphs:
434431
sublist with roman numerals, starting with 4
435432
\item
436433
more items
437-
438434
\begin{enumerate}
439435
\def\labelenumiii{(\Alph{enumiii})}
440436
\tightlist
@@ -453,20 +449,17 @@ Nesting:
453449
\tightlist
454450
\item
455451
Upper Alpha
456-
457452
\begin{enumerate}
458453
\def\labelenumii{\Roman{enumii}.}
459454
\tightlist
460455
\item
461456
Upper Roman.
462-
463457
\begin{enumerate}
464458
\def\labelenumiii{(\arabic{enumiii})}
465459
\setcounter{enumiii}{5}
466460
\tightlist
467461
\item
468462
Decimal start with 6
469-
470463
\begin{enumerate}
471464
\def\labelenumiv{\alph{enumiv})}
472465
\setcounter{enumiv}{2}
@@ -486,7 +479,6 @@ Autonumbering:
486479
Autonumber.
487480
\item
488481
More.
489-
490482
\begin{enumerate}
491483
\tightlist
492484
\item
@@ -620,7 +612,6 @@ bar
620612
Interpreted markdown in a table:
621613

622614
This is \emph{emphasized}
623-
624615
And this is \textbf{strong}
625616

626617
Here's a simple block:
@@ -765,7 +756,6 @@ Animal & Number \\ \hline
765756
Dog & 2 \\
766757
Cat & 1 \\ \hline
767758
\end{tabular}
768-
769759
\begin{center}\rule{0.5\linewidth}{0.5pt}\end{center}
770760

771761
\section{Special Characters}\label{special-characters}

test/writers-lang-and-dir.latex

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
\section{Empty Divs and Spans}\label{empty-divs-and-spans}
8383

8484
Some text and
85-
8685
div contents
8786

8887
and more text.
@@ -92,7 +91,6 @@ Next paragraph with a {span} and a word-thatincludesa{span}right?
9291
\section{Directionality}\label{directionality}
9392

9493
Some text and
95-
9694
\begin{RTL}
9795
rtl div contents
9896
\end{RTL}
@@ -109,7 +107,6 @@ word-that-includesa\LR{ltrspan}right?
109107
\section{Languages}\label{languages}
110108

111109
Some text and
112-
113110
\begin{otherlanguage}{ngerman}
114111

115112
German div contents
@@ -127,7 +124,6 @@ Some \foreignlanguage{spanish}{Spanish text}.
127124
\section{Combined}\label{combined}
128125

129126
Some text and
130-
131127
\begin{RTL}
132128
\begin{otherlanguage}{french}
133129

0 commit comments

Comments
 (0)