aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-07-20 17:08:05 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-07-20 17:12:53 -0700
commit91d4283263cc648efdd41e8c391477dd962db8ce (patch)
tree1b56617efe50f42a25c9a7a82cc8dd78544dce1f /src
parentb6f9318c9bd2117de7f567dc8f50c56260015cc8 (diff)
downloadpandoc-91d4283263cc648efdd41e8c391477dd962db8ce.tar.gz
LaTeX writer: fix line breaks at start of paragraph.
Previously we just omitted these. Now we render them using `\hfill\break` instead of `\\`. This is a revision of a PR by @sabine (#5591) who should be credited with the idea. Closes #3324.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 3acf80866..cdbdc8420 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -516,12 +516,6 @@ isListBlock (OrderedList _ _) = True
isListBlock (DefinitionList _) = True
isListBlock _ = False
-isLineBreakOrSpace :: Inline -> Bool
-isLineBreakOrSpace LineBreak = True
-isLineBreakOrSpace SoftBreak = True
-isLineBreakOrSpace Space = True
-isLineBreakOrSpace _ = False
-
-- | Convert Pandoc block element to LaTeX.
blockToLaTeX :: PandocMonad m
=> Block -- ^ Block to convert
@@ -599,7 +593,7 @@ blockToLaTeX (Div (identifier,classes,kvs) bs)
(wrapColumns . wrapColumn . wrapDir . wrapLang . wrapNotes)
<$> blockListToLaTeX bs
blockToLaTeX (Plain lst) =
- inlineListToLaTeX $ dropWhile isLineBreakOrSpace lst
+ inlineListToLaTeX lst
-- title beginning with fig: indicates that the image is a figure
blockToLaTeX (Para [Image attr@(ident, _, _) txt (src,'f':'i':'g':':':tit)]) = do
(capt, captForLof, footnotes) <- getCaption True txt
@@ -623,7 +617,7 @@ blockToLaTeX (Para [Str ".",Space,Str ".",Space,Str "."]) = do
then blockToLaTeX (RawBlock "latex" "\\pause")
else inlineListToLaTeX [Str ".",Space,Str ".",Space,Str "."]
blockToLaTeX (Para lst) =
- inlineListToLaTeX $ dropWhile isLineBreakOrSpace lst
+ inlineListToLaTeX lst
blockToLaTeX (LineBlock lns) =
blockToLaTeX $ linesToPara lns
blockToLaTeX (BlockQuote lst) = do
@@ -1083,7 +1077,7 @@ inlineListToLaTeX :: PandocMonad m
=> [Inline] -- ^ Inlines to convert
-> LW m Doc
inlineListToLaTeX lst =
- mapM inlineToLaTeX (fixLineInitialSpaces lst)
+ mapM inlineToLaTeX (fixLineInitialSpaces . fixInitialLineBreaks $ lst)
>>= return . hcat
-- nonbreaking spaces (~) in LaTeX don't work after line breaks,
-- so we turn nbsps after hard breaks to \hspace commands.
@@ -1095,6 +1089,12 @@ inlineListToLaTeX lst =
fixNbsps s = let (ys,zs) = span (=='\160') s
in replicate (length ys) hspace ++ [Str zs]
hspace = RawInline "latex" "\\hspace*{0.333em}"
+ -- We need \hfill\break for a line break at the start
+ -- of a paragraph. See #5591.
+ fixInitialLineBreaks (LineBreak:xs) =
+ RawInline (Format "latex") "\\hfill\\break\n" :
+ fixInitialLineBreaks xs
+ fixInitialLineBreaks xs = xs
isQuoted :: Inline -> Bool
isQuoted (Quoted _ _) = True