@@ -442,19 +442,22 @@ doMacros n = do
442442 Just o ->
443443 (:) <$> option o bracketedToks
444444 <*> count (numargs - 1) getarg
445− let addTok (Tok _ (Arg i) _) acc | i > 0
446− , i <= numargs =
447− foldr addTok acc (args !! (i - 1))
445+ -- first boolean param is true if we're tokenizing
446+ -- an argument (in which case we don't want to
447+ -- expand #1 etc.)
448+ let addTok False (Tok _ (Arg i) _) acc | i > 0
449+ , i <= numargs =
450+ foldr (addTok True) acc (args !! (i - 1))
448451 -- add space if needed after control sequence
449452 -- see #4007
450− addTok (Tok _ (CtrlSeq x) txt)
453+ addTok _ (Tok _ (CtrlSeq x) txt)
451454 acc@(Tok _ Word _ : _)
452455 | not (T.null txt) &&
453456 (isLetter (T.last txt)) =
454457 Tok spos (CtrlSeq x) (txt <> " ") : acc
455− addTok t acc = setpos spos t : acc
458+ addTok _ t acc = setpos spos t : acc
456459 ts' <- getInput
457− setInput $ foldr addTok ts' newtoks
460+ setInput $ foldr (addTok False) ts' newtoks
458461 case expansionPoint of
459462 ExpandWhenUsed ->
460463 if n > 20 -- detect macro expansion loops