aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2025-06-20 10:15:36 -0700
committerJohn MacFarlane <[email protected]>2025-08-26 12:41:40 +0200
commita61d3e6727d7a23eeeb0a506b1df0b6a1a4684ac (patch)
treeb5b7491a69471d71bc199780b96fdde4c60ba290
parent10404ca6d5c1fe95a9cc1e467becc01de56e3e38 (diff)
LaTeX writer: don't invariably insert blanks between blocks.issue7111
Plain or RawBlock elements should not automatically be followed by blank lines. See #7111
-rw-r--r--cabal.project5
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs49
-rw-r--r--test/writer.latex10
-rw-r--r--test/writers-lang-and-dir.latex4
4 files changed, 34 insertions, 34 deletions
diff --git a/cabal.project b/cabal.project
index a211d3417..2993edeff 100644
--- a/cabal.project
+++ b/cabal.project
@@ -21,4 +21,9 @@ source-repository-package
location: https://github.com/jgm/texmath.git
tag: 2a40f5d26d9b888559fd573ea8e7cb9c0114f9ee
+source-repository-package
+ type: git
+ location: https://github.com/jgm/doclayout.git
+ tag: eeb53975379e40166e36aec0315cd933607f2aff
+
-- TODO: release new skylighting-core, skylighting
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 2c71e689a..aced018c1 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -357,8 +357,10 @@ blockToLaTeX (Div attr@(identifier,"block":dclasses,_)
else (cr <>) <$> hypertarget identifier
title' <- inlineListToLaTeX ils
contents <- blockListToLaTeX bs
- wrapDiv attr $ ("\\begin" <> braces blockname <> braces title' <> anchor) $$
- contents $$ "\\end" <> braces blockname
+ ($$ blankline) <$> wrapDiv attr
+ (("\\begin" <> braces blockname <> braces title' <> anchor) $$
+ contents $$
+ "\\end" <> braces blockname)
blockToLaTeX (Div (identifier,"slide":dclasses,dkvs)
(Header _ (_,hclasses,hkvs) ils : bs)) = do
-- note: [fragile] is required or verbatim breaks
@@ -392,7 +394,7 @@ blockToLaTeX (Div (identifier,"slide":dclasses,dkvs)
else (cr <>) <$> hypertarget identifier
contents <- blockListToLaTeX bs >>= wrapDiv (identifier,classes,kvs)
return $ ("\\begin{frame}" <> options <> slideTitle <> slideAnchor) $$
- contents $$ "\\end{frame}"
+ contents $$ "\\end{frame}" $$ blankline
blockToLaTeX (Div (identifier@(T.uncons -> Just (_,_)),dclasses,dkvs)
(Header lvl ("",hclasses,hkvs) ils : bs)) =
-- move identifier from div to header
@@ -433,23 +435,24 @@ blockToLaTeX (Div (identifier,classes,kvs) bs) = do
| otherwise = do
linkAnchor <- hypertarget identifier
pure $ linkAnchor $$ txt
- wrapDiv (identifier,classes,kvs) result >>= wrap
+ ($$ blankline) <$> (wrapDiv (identifier,classes,kvs) result >>= wrap)
blockToLaTeX (Plain lst) =
inlineListToLaTeX lst
--- . . . indicates pause in beamer slides
+-- . . . indicates pause in beamer slides
blockToLaTeX (Para [Str ".",Space,Str ".",Space,Str "."]) = do
beamer <- gets stBeamer
if beamer
then blockToLaTeX (RawBlock "latex" "\\pause")
- else inlineListToLaTeX [Str ".",Space,Str ".",Space,Str "."]
+ else ($$ blankline) . (blankline $$)
+ <$> inlineListToLaTeX [Str ".",Space,Str ".",Space,Str "."]
blockToLaTeX (Para lst) =
if null lst
then do
opts <- gets stOptions
if isEnabled Ext_empty_paragraphs opts
- then pure "\\hfill\\par"
+ then pure $ "\\hfill\\par" $$ blankline
else pure mempty
- else inlineListToLaTeX lst
+ else (blankline $$) . ($$ blankline) <$> inlineListToLaTeX lst
blockToLaTeX (LineBlock lns) =
blockToLaTeX $ linesToPara lns
blockToLaTeX (BlockQuote lst) = do
@@ -470,7 +473,8 @@ blockToLaTeX (BlockQuote lst) = do
let envname = if csquotes then "displayquote" else "quote"
return $ ("\\begin" <> braces envname) $$
contents $$
- ("\\end" <> braces envname)
+ ("\\end" <> braces envname) $$
+ blankline
blockToLaTeX (CodeBlock (identifier,classes,keyvalAttr) str) = do
opts <- gets stOptions
inNote <- stInNote <$> get
@@ -527,7 +531,8 @@ blockToLaTeX (CodeBlock (identifier,classes,keyvalAttr) str) = do
when inNote $ modify (\s -> s{ stVerbInNote = True })
modify (\s -> s{ stHighlighting = True })
return (flush $ linkAnchor $$ text (T.unpack h))
- case () of
+ ($$ blankline) <$>
+ case () of
_ | isEnabled Ext_literate_haskell opts && "haskell" `elem` classes &&
"literate" `elem` classes -> lhsCodeBlock
| writerListings opts -> listingsCodeBlock
@@ -564,7 +569,8 @@ blockToLaTeX (BulletList lst) = do
spacing $$
-- force list at beginning of definition to start on new line
vcat items $$
- "\\end{itemize}"
+ "\\end{itemize}" $$
+ blankline
blockToLaTeX (OrderedList _ []) = return empty -- otherwise latex error
blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
st <- get
@@ -618,6 +624,7 @@ blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
$$ spacing
$$ vcat items
$$ "\\end{enumerate}"
+ $$ blankline
blockToLaTeX (DefinitionList []) = return empty
blockToLaTeX (DefinitionList lst) = do
incremental <- gets stIncremental
@@ -628,17 +635,18 @@ blockToLaTeX (DefinitionList lst) = do
then text "\\tightlist"
else empty
return $ text ("\\begin{description}" <> inc) $$ spacing $$ vcat items $$
- "\\end{description}"
-blockToLaTeX HorizontalRule =
- return
- "\\begin{center}\\rule{0.5\\linewidth}{0.5pt}\\end{center}"
+ "\\end{description}" $$
+ blankline
+blockToLaTeX HorizontalRule = return $
+ "\\begin{center}\\rule{0.5\\linewidth}{0.5pt}\\end{center}" $$ blankline
blockToLaTeX (Header level (id',classes,_) lst) = do
modify $ \s -> s{stInHeading = True}
hdr <- sectionHeader classes id' level lst
modify $ \s -> s{stInHeading = False}
- return hdr
+ return $ hdr $$ blankline
blockToLaTeX (Table attr blkCapt specs thead tbodies tfoot) =
- tableToLaTeX inlineListToLaTeX blockListToLaTeX
+ ($$ blankline) <$>
+ tableToLaTeX inlineListToLaTeX blockListToLaTeX
(Ann.toTable attr blkCapt specs thead tbodies tfoot)
blockToLaTeX (Figure (ident, _, _) captnode body) = do
opts <- gets stOptions
@@ -678,6 +686,7 @@ blockToLaTeX (Figure (ident, _, _) captnode body) = do
innards
_ -> cr <> "\\begin{figure}" $$ innards $$ "\\end{figure}")
$$ footnotes
+ $$ blankline
toSubfigure :: PandocMonad m => Int -> Block -> LW m (Doc Text)
toSubfigure nsubfigs blk = do
@@ -696,8 +705,8 @@ toSubfigure nsubfigs blk = do
]
blockListToLaTeX :: PandocMonad m => [Block] -> LW m (Doc Text)
-blockListToLaTeX lst =
- vsep `fmap` mapM (\b -> setEmptyLine True >> blockToLaTeX b) lst
+blockListToLaTeX lst = (nestle . chomp . vcat) <$>
+ mapM (\b -> setEmptyLine True >> blockToLaTeX b) lst
listItemToLaTeX :: PandocMonad m => Bool -> [Block] -> LW m (Doc Text)
listItemToLaTeX isOrdered lst
@@ -742,7 +751,7 @@ defListItemToLaTeX (term, defs) = do
firstitem <- blockToLaTeX x
modify $ \s -> s{stIsFirstInDefinition = False }
rest <- blockListToLaTeX xs
- return $ firstitem $+$ rest
+ return $ chomp . nestle $ firstitem $+$ rest
return $ case defs of
((Header{} : _) : _) ->
"\\item" <> brackets term'' <> " ~ " $$ def'
diff --git a/test/writer.latex b/test/writer.latex
index 4a268e32e..fa3072010 100644
--- a/test/writer.latex
+++ b/test/writer.latex
@@ -339,12 +339,10 @@ Multiple paragraphs:
\tightlist
\item
Tab
-
\begin{itemize}
\tightlist
\item
Tab
-
\begin{itemize}
\tightlist
\item
@@ -362,7 +360,6 @@ Here's another:
First
\item
Second:
-
\begin{itemize}
\tightlist
\item
@@ -434,7 +431,6 @@ Same thing but with paragraphs:
sublist with roman numerals, starting with 4
\item
more items
-
\begin{enumerate}
\def\labelenumiii{(\Alph{enumiii})}
\tightlist
@@ -453,20 +449,17 @@ Nesting:
\tightlist
\item
Upper Alpha
-
\begin{enumerate}
\def\labelenumii{\Roman{enumii}.}
\tightlist
\item
Upper Roman.
-
\begin{enumerate}
\def\labelenumiii{(\arabic{enumiii})}
\setcounter{enumiii}{5}
\tightlist
\item
Decimal start with 6
-
\begin{enumerate}
\def\labelenumiv{\alph{enumiv})}
\setcounter{enumiv}{2}
@@ -486,7 +479,6 @@ Autonumbering:
Autonumber.
\item
More.
-
\begin{enumerate}
\tightlist
\item
@@ -620,7 +612,6 @@ bar
Interpreted markdown in a table:
This is \emph{emphasized}
-
And this is \textbf{strong}
Here's a simple block:
@@ -765,7 +756,6 @@ Animal & Number \\ \hline
Dog & 2 \\
Cat & 1 \\ \hline
\end{tabular}
-
\begin{center}\rule{0.5\linewidth}{0.5pt}\end{center}
\section{Special Characters}\label{special-characters}
diff --git a/test/writers-lang-and-dir.latex b/test/writers-lang-and-dir.latex
index 842ca98a6..e2f6b4ce3 100644
--- a/test/writers-lang-and-dir.latex
+++ b/test/writers-lang-and-dir.latex
@@ -82,7 +82,6 @@
\section{Empty Divs and Spans}\label{empty-divs-and-spans}
Some text and
-
div contents
and more text.
@@ -92,7 +91,6 @@ Next paragraph with a {span} and a word-thatincludesa{span}right?
\section{Directionality}\label{directionality}
Some text and
-
\begin{RTL}
rtl div contents
\end{RTL}
@@ -109,7 +107,6 @@ word-that-includesa\LR{ltrspan}right?
\section{Languages}\label{languages}
Some text and
-
\begin{otherlanguage}{ngerman}
German div contents
@@ -127,7 +124,6 @@ Some \foreignlanguage{spanish}{Spanish text}.
\section{Combined}\label{combined}
Some text and
-
\begin{RTL}
\begin{otherlanguage}{french}