git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: Use `\hspace*` for nonbreaking space after line break.

Since `~` spaces after a line break are just ignored. Closes #687.

commitc29a1942d08ed73b2ffb6d29c1c614297f00e107 authorJohn MacFarlane <fiddlosopher@gmail.com> dateFri 11 Jan 2013, 20:40 (14 years ago) parent98bc0d1
1 file changed+13−1
src/Text/Pandoc/Writers/LaTeX.hs+13−1
src/Text/Pandoc/Writers/LaTeX.hs+13−1
@@ -518,7 +518,19 @@ sectionHeader ref level lst = do
518518-- | Convert list of inline elements to LaTeX.
519519inlineListToLaTeX :: [Inline] -- ^ Inlines to convert
520520 -> State WriterState Doc
521−inlineListToLaTeX lst = mapM inlineToLaTeX lst >>= return . hcat
521+inlineListToLaTeX lst =
522+ mapM inlineToLaTeX (fixLineInitialSpaces lst)
523+ >>= return . hcat
524+ -- nonbreaking spaces (~) in LaTeX don't work after line breaks,
525+ -- so we turn nbsps after hard breaks to \hspace commands.
526+ -- this is mostly used in verse.
527+ where fixLineInitialSpaces [] = []
528+ fixLineInitialSpaces (LineBreak : Str s@('\160':_) : xs) =
529+ LineBreak : fixNbsps s ++ fixLineInitialSpaces xs
530+ fixLineInitialSpaces (x:xs) = x : fixLineInitialSpaces xs
531+ fixNbsps s = let (ys,zs) = span (=='\160') s
532+ in replicate (length ys) hspace ++ [Str zs]
533+ hspace = RawInline "latex" "\\hspace*{0.4em}"
522534
523535isQuoted :: Inline -> Bool
524536isQuoted (Quoted _ _) = True