summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-01-11 20:40:00 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-01-11 20:40:00 -0800
commitc29a1942d08ed73b2ffb6d29c1c614297f00e107 (patch)
tree09dab8791ec6ac754c063b60418d6e43d51111b0 /src
parent98bc0d17ab3c31f53d7d133e3dc589fc93756c7b (diff)
LaTeX writer: Use `\hspace*` for nonbreaking space after line break.
Since `~` spaces after a line break are just ignored. Closes #687.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 4e4a2b421..35376ee99 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -518,7 +518,19 @@ sectionHeader ref level lst = do
-- | Convert list of inline elements to LaTeX.
inlineListToLaTeX :: [Inline] -- ^ Inlines to convert
-> State WriterState Doc
-inlineListToLaTeX lst = mapM inlineToLaTeX lst >>= return . hcat
+inlineListToLaTeX lst =
+ mapM inlineToLaTeX (fixLineInitialSpaces lst)
+ >>= return . hcat
+ -- nonbreaking spaces (~) in LaTeX don't work after line breaks,
+ -- so we turn nbsps after hard breaks to \hspace commands.
+ -- this is mostly used in verse.
+ where fixLineInitialSpaces [] = []
+ fixLineInitialSpaces (LineBreak : Str s@('\160':_) : xs) =
+ LineBreak : fixNbsps s ++ fixLineInitialSpaces xs
+ fixLineInitialSpaces (x:xs) = x : fixLineInitialSpaces xs
+ fixNbsps s = let (ys,zs) = span (=='\160') s
+ in replicate (length ys) hspace ++ [Str zs]
+ hspace = RawInline "latex" "\\hspace*{0.4em}"
isQuoted :: Inline -> Bool
isQuoted (Quoted _ _) = True