@@ -372,11 +372,14 @@ totoks pos t =
372372 | otherwise ->
373373 Tok pos Symbol (T.singleton c) : totoks (incSourceColumn pos 1) rest
374374
375− where isSpaceOrTab ' ' = True
376− isSpaceOrTab '\t' = True
377− isSpaceOrTab _ = False
378− isLetterOrAt '@' = True
379− isLetterOrAt c = isLetter c
375+isSpaceOrTab :: Char -> Bool
376+isSpaceOrTab ' ' = True
377+isSpaceOrTab '\t' = True
378+isSpaceOrTab _ = False
379+
380+isLetterOrAt :: Char -> Bool
381+isLetterOrAt '@' = True
382+isLetterOrAt c = isLetter c
380383
381384isLowerHex :: Char -> Bool
382385isLowerHex x = x >= '0' && x <= '9' || x >= 'a' && x <= 'f'
@@ -411,10 +414,19 @@ doMacros n = do
411414 Tok spos (CtrlSeq "end") _ : Tok _ Symbol "{" :
412415 Tok _ Word name : Tok _ Symbol "}" : ts
413416 -> handleMacros spos ("end" <> name) ts
417+ Tok _ (CtrlSeq "expandafter") _ : t : ts
418+ -> do setInput ts
419+ doMacros n
420+ getInput >>= setInput . combineTok t
414421 Tok spos (CtrlSeq name) _ : ts
415422 -> handleMacros spos name ts
416423 _ -> return ()
417− where handleMacros spos name ts = do
424+ where combineTok (Tok spos (CtrlSeq name) x) (Tok _ Word w : ts)
425+ | T.all isLetterOrAt w =
426+ Tok spos (CtrlSeq (name <> w)) (x1 <> w <> x2) : ts
427+ where (x1, x2) = T.break isSpaceOrTab x
428+ combineTok t ts = t:ts
429+ handleMacros spos name ts = do
418430 macros <- sMacros <$> getState
419431 case M.lookup name macros of
420432 Nothing -> return ()
@@ -439,6 +451,7 @@ doMacros n = do
439451 else doMacros (n + 1)
440452 ExpandWhenDefined -> return ()
441453
454+
442455setpos :: SourcePos -> Tok -> Tok
443456setpos spos (Tok _ tt txt) = Tok spos tt txt
444457