LaTeX writer: Use \hspace* for nonbreaking space after line break.

Since `~` spaces after a line break are just ignored.
Closes #687.
This commit is contained in:
John MacFarlane 2013-01-11 20:40:00 -08:00
parent 98bc0d17ab
commit c29a1942d0

View file

@ -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