From 4dcf5d5db3b249f09a264402bebda44280dc9706 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 8 Sep 2026 20:43:09 +0000 Subject: [PATCH] LaTeX reader: peek at next token directly in peekTok. peekTok went through lookAhead (satisfyTok (const True)), paying for tokenPrim position bookkeeping, the raw-token state update, and lookAhead state save/restore on every call; peekTok is used by the main inline and block dispatchers for every element. Just examine the head of the input stream after expanding macros. Co-Authored-By: Claude --- src/Text/Pandoc/Readers/LaTeX/Parsing.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs index 3a6788aea..df7e7445c 100644 --- a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs +++ b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs @@ -579,7 +579,10 @@ satisfyTok f = do peekTok :: PandocMonad m => LP m Tok peekTok = do doMacros - lookAhead (satisfyTok (const True)) + TokStream _ toks <- getInput + case toks of + t : _ -> return t + [] -> mzero doMacros :: PandocMonad m => LP m () doMacros = do