git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: insert space when needed in macro expansion.

Sometimes we need to insert a space after a control sequence to prevent it merging with a following letter. Closes #4007.

commit90597fe292a84959d289fe17eae226c7e8bf23c8 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 30 Oct 2017, 11:51 (9 years ago) parent272b833
1 file changed+8−1
src/Text/Pandoc/Readers/LaTeX.hs+8−1
src/Text/Pandoc/Readers/LaTeX.hs+8−1
@@ -438,7 +438,14 @@ doMacros n = do
438438 <*> count (numargs - 1) getarg
439439 let addTok (Tok _ (Arg i) _) acc | i > 0
440440 , i <= numargs =
441− map (setpos spos) (args !! (i - 1)) ++ acc
441+ foldr addTok acc (args !! (i - 1))
442+ -- add space if needed after control sequence
443+ -- see #4007
444+ addTok (Tok _ (CtrlSeq x) txt)
445+ acc@(Tok _ Word _ : _)
446+ | not (T.null txt) &&
447+ (isLetter (T.last txt)) =
448+ Tok spos (CtrlSeq x) (txt <> " ") : acc
442449 addTok t acc = setpos spos t : acc
443450 ts' <- getInput
444451 setInput $ foldr addTok ts' newtoks