Repository navigation
tex-expansion round 2 - #98
Merged
Merged
Conversation
New crate crates/tex-expansion implementing catcodes+tokenizer, def/edef/gdef/xdef/let/futurelet, expandafter/noexpand/csname, TeX and e-TeX conditionals (if/ifx/ifnum/ifdim/ifodd/ifcase/newif/unless), grouping with global/aftergroup, count/dimen/skip/toks registers with countdef family and numexpr/dimexpr, and a LaTeX layer (newcommand/renewcommand/provide, newenvironment, counters, @ifnextchar/@ifstar/@namedef/@nameuse). 45 unit tests passing. Implementation-Agent: Claude Fable 5.1 (subagent kabir-claude KC-101, mac-m5pro-kabir) Commit-Executor: Claude Code direct Git Co-Authored-By: Claude Fable 5.1 <[email protected]>
…orpus
Fixes found via a 108-case oracle corpus run against real tex/etex/pdflatex:
bare grouping braces must not appear in the content-token stream (matches
real main-control semantics, not \write's scan_toks semantics); \the\dimen
must render via TeX's print_scaled algorithm, not raw sp; \numexpr division
rounds to nearest (ties away from zero); \ifcase must keep skipping on a
negative selector; \setcounter/\addtocounter values may contain expandable
constructs like \value{...}; \count's "..." hex parsing.
Adds tests/oracle/ (generator script + committed manifest.json + expected
fixtures, gitignored tmp/) and CONTRACT.md proposing the crates/compiler
adoption path, known deviations from real TeX, and what's done vs not.
47 unit tests + 108/108 oracle cases green.
Implementation-Agent: Claude Fable 5.1 (subagent kabir-claude KC-101, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Uncommitted progress from the Fable round-2 session (KC-101 r2), saved when the session was paused to stay inside the 5-hour usage window. Not reviewed or re-tested; resume from here. Implementation-Agent: Claude Fable 5.1 (headless agent kabir-claude KC-101 r2, mac-m5pro-kabir) Commit-Executor: Claude Opus 5 (coordinator session, direct Git) Co-Authored-By: Claude Fable 5.1 <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
…-case oracle) WIP, pushed early on coordinator request; not final. Known open item at this commit: one unit/incremental test run hung after the conditional test-phase change (under investigation); grouping braces not yet emitted. Review fixes to 7dae933: \ifcsname/\@ifundefined true after group restore (is_defined), print_cs spacing per tex.web 262, \detokenize doubles #, \protect/let-to-relax emitted as \relax, incremental checkpoint diag/label offsets were relative after restore, \outer recovery loop in parameter text (Missing { inserted), prefix errors ("You can't use a prefix with"), \newcommand optional args built as LaTeX does (\@Protected@testopt + \\foo[#1]), \newcommand on a defined name keeps the old meaning, zero-arg commands not \long, \expanded, \pdfstrcmp, \eTeXversion, coefficient dimens (.5\dimen0), extra-} argument recovery, \fi during a test inserts \relax, INITEX constructor. Adds oracle modes latex-write/latex-doc/*-err, incremental equivalence tests, keystroke bench, smoke and kernel probes. Implementation-Agent: Claude Opus 5 (subagent kabir-claude KC-101 r2, mac-m5pro-kabir) Commit-Executor: Claude Code direct Git Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…sion Grouping braces (explicit and implicit \bgroup/\egroup) and \begingroup/\endgroup are now emitted in the output stream with their source spans (coordinator request from KC-110/PR #96); \aftergroup tokens follow the closing brace. API-compatible: is_group_token() added for consumers that want content only. Nested expansion (edef bodies, macro calls) now counts toward max_expansion_steps, fixing a hang found by the incremental random-edit test; finished token lists are popped before pushing so tail recursion does not grow the input stack. Tests: 52 unit, 3 incremental equivalence, 415/415 oracle. Implementation-Agent: Claude Opus 5 (subagent kabir-claude KC-101 r2, mac-m5pro-kabir) Commit-Executor: Claude Code direct Git Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…/I-O, \input via host reader Lexer: physical line breaks stand for \endlinechar (incl. -1 and non-EOL catcodes such as \obeylines), CRLF counts once, trailing spaces stripped (input_ln), ^^M inside a line discards the rest, ^^ notation resolved in control-sequence names, fixed a length underflow that made ^^ notation panic past byte 0. INITEX mode (kernel probe only): TeX/e-TeX/pdfTeX parameters as registers, \immediate/\write/\openout/\message/\errmessage/\read stand-ins, \eTeXversion/\eTeXrevision/\jobname. Engine::set_file_reader makes \input read files (otherwise it still passes through). Tests: 55 unit, 3 incremental equivalence, 415/415 oracle. Implementation-Agent: Claude Opus 5 (subagent kabir-claude KC-101 r2, mac-m5pro-kabir) Commit-Executor: Claude Code direct Git Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…oup tokens Physical line breaks are recognised by the lexer, so the catcode tables no longer mark \n as end-of-line; ^^J inside \write/\typeout text is an ordinary character as in real TeX. With this the latex.ltx probe loads texsys.cfg, expl3.ltx and expl3-code.tex and reaches line 1147. Implementation-Agent: Claude Opus 5 (subagent kabir-claude KC-101 r2, mac-m5pro-kabir) Commit-Executor: Claude Code direct Git Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…e ignores group tokens CONTRACT.md documents the round-2 API, output-stream contract (grouping tokens), oracle modes (415/415), \long/\outer, counters, \fnsymbol mapping, incremental design and latency (500 KB: p50 5.9 ms, p95 115 ms), smoke over origin/main (42/44 clean) and the latex.ltx kernel probe (line 1147/22470, 130/310 primitives missing, mostly typesetting). Implementation-Agent: Claude Opus 5 (subagent kabir-claude KC-101 r2, mac-m5pro-kabir) Commit-Executor: Claude Code direct Git Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
This was referenced Sep 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Round 2 of KC-101, extending #88 (which stays open). Branch
agent/kabir-claude/tex-expansion-r2-opus, based on the paused Fable WIP 7dae933. Onlycrates/tex-expansion/**is touched. Full details are incrates/tex-expansion/CONTRACT.md.Review of 7dae933 (the Fable WIP)
The WIP built and its tests passed, but it had no tests for its new features:
tests/incremental_tests.rsandexamples/bench_incremental.rswere referenced but missing. Bugs found and fixed:\ifcsnameand\@ifundefinedwere true after a group restore.\detokenizedid not double#.print_csspacing did not follow tex.web §262.\protectleaked into the output.\outertoken in parameter text caused an infinite loop.\global x.^^notation panicked past byte 0 (the pre-existing bug fix is also applied).\edefdid not count toward the step limit, so it could hang.\newcommandon a defined name redefined it.Results
latex-write,latex-doc, andtex-err/etex-err/latex-err, which compare TeX's own! ...error lines. Coverage includes the full requested list:\@ifundefined,\DeclareRobustCommand/\protected@edef,\unexpanded/\detokenize/\expanded,\ifdefined/\ifcsname,\scantokens,\afterassignment,\uppercasewith\uccode,\chardef/\mathchardef,\futureletidioms,\@for/\@tfor,\loop,\g@addto@macro,\AtBeginDocument, keyval, lengths,\refstepcounter/\@currentlabel,\csnamerelax,\string/\escapechar,\meaningof every token kind,\pdfstrcmp.\long/\outer: enforced as in tex.web §336/§392-399, with TeX's messages and recovery. Covers runaway\par, forbidden control sequences in definitions, arguments, texts and skipped conditionals, extra}, and "doesn't match its definition"; all checked against the real logs.[within],\@addtoreset/\@removefromreset,\counterwithin(*)/\counterwithout(*), and recursive resets are all oracle-checked.\fnsymbolproduces Unicode (∗ † ‡ § ¶ ‖ ∗∗ †† ‡‡), which matches pdflatex's extracted text.{/}(explicit or implicit),\begingroupand\endgroupare now emitted with spans, as requested by KC-110/WIP: engine PoC (KC-110, paused) #96. API-compatible, withis_group_tokenadded.IncrementalExpanderequals a full run (tokens with spans, labels and diagnostics) under random edits on all oracle docs, HW1/HW2, and a macro-heavy document. On a 500 KB synthetic document: p50 5.9 ms, p95 115 ms, max 379 ms per keystroke, with 536/600 edits converging early..texfiles underfixtures/andtests/on origin/main were run; 42 are clean and 2 have errors, both legitimate. The most common unmodelled primitives are\parindent,\parskip,\hfill,\input,\left/\right.latex.ltxrun from an INITEX-state engine gets through line 1147 of 22470 (5.1%) in 226 ms, reading texsys.cfg, expl3.ltx and expl3-code.tex. It stops in the expl3 bootstrap, which needs the full pdfTeX primitive set. Static gap: 130 of the 310 primitiveslatex.ltxreferences are missing (515 of 717 including expl3, 162 of them LuaTeX-only), and they are mostly box, font, math and alignment primitives. So loading the kernel needs a typesetting core, not just more expansion work (see CONTRACT.md for the estimate).\endlinechar(including -1 and active^^M), CRLF, trailing-space stripping, and^^in control-sequence names.Engine::set_file_readermakes\inputread files.Tests
cargo test: 55 unit, 3 incremental-equivalence, 415 oracle.🤖 Generated with Claude Code
https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu