@@ -438,7 +438,14 @@ doMacros n = do
438 <*> count (numargs - 1) getarg
438 <*> count (numargs - 1) getarg
439 let addTok (Tok _ (Arg i) _) acc | i > 0
439 let addTok (Tok _ (Arg i) _) acc | i > 0
440 , i <= numargs =
440 , 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
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
442 addTok t acc = setpos spos t : acc
449 addTok t acc = setpos spos t : acc
443 ts' <- getInput
450 ts' <- getInput
444 setInput $ foldr addTok ts' newtoks
451 setInput $ foldr addTok ts' newtoks