Skip to content

engine: \ProcessOptions optional-star peek must not strand the following token - #18

Merged
tannevaled merged 1 commit into
mainfrom
agentA-processoptions-peek-strand
Aug 17, 2026
Merged

tannevaled merged 1 commit into
mainfrom
agentA-processoptions-peek-strand

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Fixes a whole-document swallow (0 pages) on svjour/epj papers such as arXiv 2604.26376.

Root cause

peekStar() (used by \ProcessOptions and \DeclareOption) does a destructive lookahead for a *: skipOptSpace() + getNext() + back(). When no star follows, the peeked token is back()-ed into a pending token list — ahead of the base input it was scanned from.

That is harmless until \ProcessOptions executes a class option whose code \inputs a companion file. svjour’s [epj] option runs:

\DeclareOption*{\InputIfFileExists{sv\CurrentOption.clo}{\let\journalopt\CurrentOption}{...}}

which splices svepj.clo into the base at the mouth position — landing it between the stranded token and the base tokens that followed it. svjour’s very next source line is:

\ProcessOptions
\ifx\journalopt\@empty ... \fi

\ProcessOptions peeks for a star, reads and strands the following \ifx, then loads svepj.clo. When the stranded \ifx finally runs, its operands are no longer \journalopt\@empty but the freshly-spliced file’s first token, \ProvidesFile{...}. The mismatched \ifx is false and skips to end-of-file (the runaway aggravated by \let\if@runhead\iftrue / \let\if@smartand\iftrue operands being counted during the skip), discarding the entire main vertical list → 0 pages.

Fix

Make the optional-star lookahead non-destructive: snapshot the input with markInput(), and on a non-star token restoreInput() instead of back(). The input is left exactly as it stood, so a later file splice cannot slip in between the peeked token and what follows it.

Verification

  • New regression test TestProcessOptionsPeekDoesNotStrandFollowingToken reproduces the svjour/epj structure (class with \DeclareOption*{\InputIfFileExists{sv\CurrentOption.clo}{...}}, \ProcessOptions immediately followed by \ifx\journalopt\@empty, plus a companion svepj.clo). It fails before the fix (body swallowed, 0 pages) and passes after.
  • arXiv 2604.26376 (main.tex, svjour/epj): 0 → 57 pages (173k glyph paths).
  • Full go test ./... green; gofmt clean.

🤖 Generated with Claude Code

…oken

peekStar() looked ahead for \ProcessOptions* with skipOptSpace()+getNext()+
back(): when no star followed, the peeked token was pushed back into a pending
token list, ahead of the base input it was scanned from. That is invisible until
\ProcessOptions then executes a class option whose code \input's a file. svjour's
[epj] option runs \InputIfFileExists{svepj.clo}{\let\journalopt\CurrentOption}{},
which splices svepj.clo into the base at the mouth position — landing it BETWEEN
the stranded token and the base tokens that followed. svjour's next source line,
\ifx\journalopt\@empty, had already had its \ifx peeked and stranded, so \ifx
bound to the loaded file's first token (\ProvidesFile{...}) instead of
\journalopt. The mismatched \ifx skipped to end-of-file, discarding the whole main
vertical list: the paper rendered 0 pages (arXiv 2604.26376, svjour/epj).

Make the optional-star lookahead non-destructive: snapshot the input with
markInput(), and on a non-star token restoreInput() instead of back(), leaving the
input exactly as it stood so a later file splice cannot slip in between the peeked
token and what follows it.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@tannevaled
tannevaled merged commit 9f9e29f into main Aug 17, 2026
9 checks passed
@tannevaled
tannevaled deleted the agentA-processoptions-peek-strand branch August 17, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant