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.
This commit is contained in:
John MacFarlane 2017-10-30 11:51:49 -07:00
parent 272b833ad5
commit 90597fe292

View file

@ -438,7 +438,14 @@ doMacros n = do
<*> count (numargs - 1) getarg <*> count (numargs - 1) getarg
let addTok (Tok _ (Arg i) _) acc | i > 0 let addTok (Tok _ (Arg i) _) acc | i > 0
, i <= numargs = , i <= numargs =
map (setpos spos) (args !! (i - 1)) ++ acc foldr addTok acc (args !! (i - 1))
-- add space if needed after control sequence
-- see #4007
addTok (Tok _ (CtrlSeq x) txt)
acc@(Tok _ Word _ : _)
| not (T.null txt) &&
(isLetter (T.last txt)) =
Tok spos (CtrlSeq x) (txt <> " ") : acc
addTok t acc = setpos spos t : acc addTok t acc = setpos spos t : acc
ts' <- getInput ts' <- getInput
setInput $ foldr addTok ts' newtoks setInput $ foldr addTok ts' newtoks