Skip to content

tikz: the picture environment starts, and a class loads its size file - #3

Merged
tannevaled merged 1 commit into
mainfrom
fix/tikz-startup
Aug 17, 2026
Merged

tannevaled merged 1 commit into
mainfrom
fix/tikz-startup

Conversation

@tannevaled

@tannevaled tannevaled commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Continuation: \begin{tikzpicture} starts and \draw draws. TikZ lines, rectangles and circles reach the page at the right coordinates, with their color and their thickness.

Eight more divergences, measured before the fix

Rule What was breaking
\active (plain TeX's name for category 13) — missing tikz makes ; active a third of the way into its file: the block failed and everything that followed was lost, hence \draw never installed
The \input file name is expanded pgf loads its modules via \input{pgfmodule\[email protected]} → no module was loading (hence \pgfnodeparttextbox missing)
The lines of an \input are counted out of the document's numbering otherwise an error points hundreds of lines too far
\csname creates its \relax locally this is how pgf asks whether it is running under LuaTeX; a lingering answer made it emit its Lua branch — hundreds of lines of Lua on the page
\lccode/\uccode = real tables, \lowercase goes through them pgfmath builds its parser this way
\colorlet[named]{…} (xcolor's optional argument) [named] landed on the page
Standard colors published in readable form \draw[red] was not recognized as a color
\setlength{\skip\footins}{…} and \@settopoint a class leaked its values onto the page

Cleanliness result: loading tikz used to dump 620 KB of package internals onto the page; it now dumps none (8,570 bytes versus 8,564 without tikz).

And a deep bug revealed along the way

Arithmetic did not work on the dimension parameters that the engine models as primitives rather than registers: \advance\hsize did nothing and \divide\hsize\p@ gave garbage. This only surfaced once the class actually loaded its size file (its name is built by a macro, so it had never been resolved): the computed text width came out at 1 pt, which truncated every paragraph. A document now gets the geometry its class computes (345 pt for article 10 pt on letter paper).

Verification

  • 761 tests pass, 0 skips, 0 failures; go vet and gofmt clean.
  • Conformance ratchet, corpus, and scripts/fidelity.sh --check (gotex vs real LaTeX): OK — the latter caught the text-width regression, which is fixed.
  • New code at 100% coverage.

Remaining for milestone (c): \node runs without error but the figure is not emitted.

\begin{tikzpicture} now runs and \draw draws: TikZ lines, rectangles and
circles reach the page at the right coordinates, with their colour and
thickness. Eight more places where the engine answered differently from TeX,
each found by running the real sources and, where TeX's own answer was in
question, measured against a real TeX first.

\active — plain TeX's name for category 13 — was missing. A package makes a
character active by name (\catcode`\;=\active), and tikz does so a third of
the way through its file; the block failed and everything defined after it
was lost with it, which is why \draw was never installed.

A file name is expanded as it is read, as TeX's file-name scanner does. pgf
loads each of its modules with \input{pgfmodule\[email protected]}, so a
literal reading found no file and the module silently never loaded — that is
where \pgfnodeparttextbox and the whole shapes module went. The lines of an
\input file are now discounted from the document's own numbering too, as a
class's already were, so an error still points at the right line.

A name \csname brings into existence means \relax, and that definition is
LOCAL. A package asks whether a control sequence exists by expanding \csname
inside a group it then closes, so the question leaves no trace; defining it
globally made every later test answer "yes". pgf asks that way whether it is
running under LuaTeX — and then emitted its Lua branch, hundreds of lines of
Lua onto the page.

\lccode/\uccode are real tables that \lowercase/\uppercase map through, which
is how a package substitutes one character for another (pgfmath builds its
parser's catcode block that way). \colorlet takes xcolor's optional model
argument, which pgf passes whenever the source colour is a named one, and the
standard colour names are published in readable form so \draw[red] is
recognised as a colour at all. \setlength assigns a register reference such
as {\skip\footins}, and \@settopoint rounds a length to whole points.

Together these leave the page clean: loading tikz used to deposit 620 KB of
package internals on it, and now deposits nothing.

Arithmetic finally works on the dimension parameters the engine models as
primitives of its own rather than as registers. \advance\hsize did nothing
and \divide\hsize\p@ produced nonsense — which only surfaced once the class
really loaded its size option file (the file name is built from a macro, so
it had never resolved before): the computed text width came out as one
point, truncating every paragraph. A document now gets the geometry its
class computed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@tannevaled
tannevaled merged commit 2ee7943 into main Aug 17, 2026
18 checks passed
tannevaled added a commit that referenced this pull request Aug 26, 2026
\newcommand\foo[\somecount]{…} defined a command of ZERO arguments. The reader
walked the bracket's tokens, kept the digits and skipped everything else, so a
count that arrived as a register — or as \the<register> — read as nothing.

That is not a missing feature, it is silent damage: the command then consumed
none of the arguments its caller passed, and each one was left in the input and
TYPESET. beamer generates its whole overlay layer this way,

	\newcommand\csname beamerx@…\endcsname[\beamer@argscount]{#3}

so every \defbeamertemplate printed its template body onto the page instead of
storing it. An empty beamer document came out 5 pages of that debris; it is now
2. The same shift also mis-bound the arguments further down the chain — the
overlay specification \beamer@sortzero passes as {} was picked up as the first
real argument, so \defbeamertemplate{tst}{fam}{…} built its key as
\beamer@@Tmpop@@tst instead of \beamer@@Tmpop@tst@fam.

A bracket holding a control sequence now goes to the engine's own integer
scanner, on an isolated input stack so nothing it leaves unread escapes into the
document. A bracket of plain digits keeps the old path.

One test expectation moves. It asserted that \newcommand\c[\relax 1]{…} takes
ONE argument — digits kept, control sequences ignored. Real LaTeX does not do
that: it scans a number, raises "Missing number, treated as zero", and defines a
command of no arguments. Checked with tectonic, which also confirms the register
form: \newcount\nn \nn=1 \newcommand\ca[\nn]{<#1>} makes \ca{X} give <X>.
tannevaled added a commit that referenced this pull request Aug 27, 2026
…mes expand (#99)

Two defects that turn out to be one story: no beamer theme had ever been loaded,
and every keyval value was silently lost.

1. \@ifnextchar does not INSERT the branch it picks — it stores it first.
   ltdefns.dtx:

	\long\def\@ifnextchar#1#2#3{\let\reserved@d=#1
	  \def\reserved@a{#2}\def\reserved@b{#3}\futurelet\@let@token\@ifnch}

   and \def\reserved@b{#3} SCANS the branch as a macro body, which halves ## a
   second time (tex.web §479: a # followed by a # stores one #). This engine's
   \@ifnextchar is a primitive that inserted the branch verbatim, skipping it.

   keyval is built on exactly that:

	\def\define@key#1#2{\@ifnextchar[{\KV@def{#1}{#2}}{\long\@namedef{KV@#1@#2}####1}}

   The #### is halved once into \define@key's own body and a second time by
   \@ifnextchar, leaving the one # that \def reads as the parameter text #1.
   Without it the generated macro's parameter text was ##1 and bound nothing:
   \setkeys{fam}{k=VAL} gave <<>>. Real LaTeX gives \long macro:#1-><<#1>> where
   this engine gave macro:##1-><<#1>>. \@ifstar and \@ifnextbracket pick their
   branch the same way and are halved for the same reason.

2. \usepackage, \documentclass and \LoadClass now EXPAND their {name}. Checked in
   one line: \def\nm{marker}\usepackage{zz\nm} loads zzmarker.sty in real LaTeX
   and loaded nothing here. beamer builds every theme file name that way —
   \beamer@calltheme does \usepackage[{#1}]{beamertheme\beamer@themename} — so
   \usetheme{default} asked for a package literally named
   "beamertheme\beamer@themename".

Together: the frametitle template (beamerouterthemedefault.sty) finally exists, so
a FRAME TITLE renders; and because key values no longer leak, the theme files stop
contributing four pages of debris. On the minimal document that is exactly the
reference — n frames make n pages, title and body both present, page 364.2x273.15.

Measured over 200 real beamer talks: 0 content lost, pages 1061 -> 1095, vector
paths 155106 -> 174863. Eight documents stop producing a sized page and each was
checked by hand: four are corpus FRAGMENTS with no \begin{document} (0 pages is
what real LaTeX gives them), one is a talk with no frame at all, one is a fragile
frame whose verbatim body this engine cannot render either way, one is unchanged
when re-run cold, and one (039a234b02c5…) trips the runaway guard on main TOO —
the guard now fires sooner, so 40KB of debris becomes none. Over 200 arXiv papers:
the single apparent loss renders 2.46MB in both binaries when re-run cold; it had
exceeded the sweep's time cap.
tannevaled added a commit that referenced this pull request Aug 30, 2026
…#129)

\end<name> can reach the terminator a body scanner is hunting through ONE more
parameterless macro, not only as its first token. beamer's columns are built that
way (beamerbaseframecomponents.sty):

	\newcommand<>\beamer@columncom[2][\beamer@colmode]{%
	  \beamer@colclose
	  \def\beamer@colclose{\end{minipage}\hfill\end{actionenv}\ignorespaces}%
	  \begin{actionenv}#3\begin{minipage}…}

so \column opens a minipage and STORES its \end{minipage} in \beamer@colclose, to
run at the next \column or at \end{columns}. \endcolumns therefore begins with
\beamer@colclose, not with \end, and the scanner stores the \end{columns} raw and
carries on — off the end of the file it is reading and into the document behind
it. Six lines rendered ZERO pages (issue #127):

	\begin{frame}[fragile]{A}
	\begin{columns}
	\column{0.5\textwidth}
	gauche
	\end{columns}
	\end{frame}

The scan now remembers where it stored its last \end{other}. When it is about to
leave the file it began in, and that \end leads somewhere after all, it rewinds
the body to that point, puts the stored tail back, and expands \end<other> in
place. Nothing is re-EXECUTED: what goes back was gathered, never run.

That distinction is the whole design, and two other shapes were measured first:

  - Applying the deeper rule EAGERLY fixes the same case and costs 28 pages over
    200 talks, one of them from 17 pages to 1; the error against 80 tectonic PDFs
    rises from 70 to 71. It runs environments' terminators early.
  - Restoring the input and re-running the whole scan is unsound: a failed scan
    has already closed groups (\gotex@endenv) and expanded macros, and putting
    the INPUT back undoes none of it. \begin{multicols}{2}\end{multicols} shows
    it — \scanOptBracketToks peeks for the optional [ WITH expansion, so the \end
    is already \csname endmulticols\endcsname + \gotex@endenv{multicols} before
    the collector starts, and a second pass closes one group too many.

Measured over 200 talks and 200 arXiv papers: not one document changes — 1197
pages and 202 558 glyphs on one side, 4253 and 9 561 555 on the other, identical
before and after, and the absolute page error against the 80 talks with a
tectonic PDF stays at 70. It closes a hole rather than moving anything.
tannevaled added a commit that referenced this pull request Aug 31, 2026
\newcommand{\cmd}[n][default] makes the FIRST of the n parameters optional: \cmd is
\@Protected@testopt, which supplies {default} when no [ follows (latex.ltx:1187-1199,
\@xargdef), and the remaining n-1 are grabbed as usual. The token path already does
this (engine.go's optArg/optDefault); the maths source path read all n as MANDATORY.

That is worse than not expanding at all. With the optional argument written out the
macro still "matched", by taking the brackets themselves as arguments:

	\qbin [p]{N}{k}  ->  \genfrac []{0pt}{}{p}{]}_{[}{N}{k}
	\qbin {N}{k}+1   ->  \genfrac []{0pt}{}{k}{+}_{N}1

so the formula came out silently wrong, the + of an expression becoming an argument.
Without it, nothing matched and the formula was dropped — which is how a paper's own
\newcommand{\qbinom}[3][q]{\genfrac[]{0pt}{}{#2}{#3}_{#1}} lost 12 equations.

Measured over 200 arXiv papers and 200 beamer talks: 5 documents change for +1234
glyphs. One repaginates, 362 -> 363 against tectonic's 333 — a document already 29
pages long of it — and the page error against the 157 renders moves 669 -> 670.
beamer does not move by one glyph.
tannevaled added a commit that referenced this pull request Aug 31, 2026
…lumns} (#176)

beamer opens a column's minipage and defers its \end into \beamer@colclose
(beamerbaseframecomponents.sty:281-283):

	\newcommand<>\beamer@columncom[2][\beamer@colmode]{%
	  \beamer@colclose
	  \def\beamer@colclose{\end{minipage}\hfill\end{actionenv}\ignorespaces}%
	  \begin{actionenv}#3…\begin{minipage}…}

so the \end this scan hunts arrives through the NEXT \column, or through
\end{columns} (:237, \endcolumns begins with \beamer@colclose). A raw scan sees
neither: \column takes arguments where the narrow expandsToEnd rule only reaches
parameterless macros, and \end{columns} is stored as somebody else's \end.

Read raw, the first column swallowed its sibling and everything after the frame. A
talk with two columns in a [fragile] frame rendered ONE page of its seven; issue #127
found this and #129 caught only the case where the frame's own file ends there.

Both are now read as what they are: at \column the body ends and \beamer@colclose is
emptied, its \end{minipage} having just been honoured (which is what beamer itself
does after running it, :269); at \end{columns} the \end<columns> body is pushed so
\beamer@colclose, and then its \end{minipage}, surface for the depth bookkeeping.

Measured over 200 beamer talks and 200 arXiv papers: 5 talks change, two of them
moving CLOSER to tectonic and none further — one 1 -> 5 pages (tectonic 7, +2268
glyphs), one 2 -> 4, exactly tectonic's. beamer gains 2885 glyphs and its page error
against the 80 tectonic renders falls 48 -> 42, with one more exact match. arXiv does
not move by one glyph.
tannevaled added a commit that referenced this pull request Sep 6, 2026
\@setfontsize is the hook every size command goes through — latex.ltx:10003-10007
reads its three arguments as \fontsize{#2}{#3}\selectfont — and ours threw #2, the
size, away. Every class size option file redefines all ten commands through it:

	\DeclareRobustCommand\large{\@setfontsize\large\@xiipt{14}}   size11.clo:82

so all ten redefinitions landed as no-ops. A document that loaded article.cls came
out with ONE font size in the whole PDF: a probe of \tiny through \Huge at [10pt]
wrote `/F0 10 Tf` and nothing else, \Huge 57% too narrow and \tiny 51% too wide.

\gotex@fontsizeat now puts the font at the size the table states, read against the
size the same table states for \normalsize (\gotex@classnormalsize), so a caller's
Options.Size still picks the body size and the table supplies the ratios. That
matters because the table is NOT a scale factor: size10.clo:82-86 and
size11.clo:82-86 are identical, so \large…\Huge are the same points in a 10pt and
an 11pt class, and size12.clo caps \Huge at \@xxvpt — the same 24.88pt as \huge.
Scaling one ladder by the class base instead would have made every 11pt heading
8-11% too large and \Huge in a 12pt class 21% too large.

The kernel's own number macros were copied rounded (\@xxpt as 20 against 20.74,
\@xxvpt as 25 against 24.88); they are now latex.ltx:7852-7863 verbatim, which is
what the ladder reads.

Measured against tectonic on the same probe, mean |error| over the ten sizes at
[10pt]/[11pt]/[12pt]: 28.8% → 5.5%. What is left is optical design sizes — cmr5
is not cmr10 shrunk — which is a different subject.

Co-Authored-By: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Sep 6, 2026
\@setfontsize is the hook every size command goes through — latex.ltx:10003-10007
reads its three arguments as \fontsize{#2}{#3}\selectfont — and ours threw #2, the
size, away. Every class size option file redefines all ten commands through it:

	\DeclareRobustCommand\large{\@setfontsize\large\@xiipt{14}}   size11.clo:82

so all ten redefinitions landed as no-ops. A document that loaded article.cls came
out with ONE font size in the whole PDF: a probe of \tiny through \Huge at [10pt]
wrote `/F0 10 Tf` and nothing else, \Huge 57% too narrow and \tiny 51% too wide.

\gotex@fontsizeat now puts the font at the size the table states, read against the
size the same table states for \normalsize (\gotex@classnormalsize), so a caller's
Options.Size still picks the body size and the table supplies the ratios. That
matters because the table is NOT a scale factor: size10.clo:82-86 and
size11.clo:82-86 are identical, so \large…\Huge are the same points in a 10pt and
an 11pt class, and size12.clo caps \Huge at \@xxvpt — the same 24.88pt as \huge.
Scaling one ladder by the class base instead would have made every 11pt heading
8-11% too large and \Huge in a 12pt class 21% too large.

The kernel's own number macros were copied rounded (\@xxpt as 20 against 20.74,
\@xxvpt as 25 against 24.88); they are now latex.ltx:7852-7863 verbatim, which is
what the ladder reads.

Measured against tectonic on the same probe, mean |error| over the ten sizes at
[10pt]/[11pt]/[12pt]: 28.8% → 5.5%. What is left is optical design sizes — cmr5
is not cmr10 shrunk — which is a different subject.

Co-authored-by: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Sep 7, 2026
…set (#312)

* xcolor: \definecolor takes two optional arguments, and both were typeset

    \def\definecolor{\@testopt{\XC@definecolor}{}}
    \def\XC@definecolor[#1]#2{\@testopt{\XC@definec@lor[#1]{#2}}\colornameprefix}
    \def\XC@definec@lor[#1]#2[#3]#4#5{…}          xcolor.sty:473-476

so the signature is \definecolor[type]{name}[prefix]{model}{spec}. We read only the
three mandatory arguments, so a call carrying either optional one was left whole in
the input and every token of it reached the page.

acmart declares its palette that way (acmart.cls:561-568), so eight lines of

    [named]ACMBluecmyk1,0.1,0,0.1 [named]ACMYellowcmyk0,0.16,1,0 …

came out on page 1 of every acmart paper in the corpus.

The type and the prefix decide which colour STACK a name lands on in xcolor; this
engine keeps one flat table, so they are consumed and dropped. The colour itself is
defined either way, which is what a renderer needs.

Measured over the 157-paper corpus: Sigma 344 -> 343 (-1), glyphs -2357.

Every one of the nine papers the harness flags loses about 260 glyphs, and on each
one those glyphs ARE the palette: on 2301.08336 the words that disappear are exactly
[named]ACMBlue…, [named]ACMYellow…, [named]ACMOrange…, [named]ACMRed…,
[named]ACMLightBlue…, [named]ACMGreen…, [named]ACMPurple…, [named]ACMDarkBlue… —
319 characters of a class's colour declarations that were never text.

Co-Authored-By: Claude Opus 5 <[email protected]>

* gofmt: a stray blank line left by #309

Co-Authored-By: Claude Opus 5 <[email protected]>

---------

Co-authored-by: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Sep 8, 2026
…und (#322)

* engine: name the macro whose call a \par abandoned (#315)

The runaway alarm counted abandoned calls but never said WHICH macro was
being read, so 198 of them over 22 corpus papers were a sum with no handle
on it — the same fault #262 repaired for the maths layer, where every
dropped formula was filed as "$math$".

parEndsArgument now records e.expandingCS, set immediately before the
argument scan in getXToken's mMacro case, and Diagnostics carries the
tally by name. cmd/gotex prints it under the existing WARNING.

Co-Authored-By: Claude Opus 5 <[email protected]>

* engine: \@hangfrom must be \long, or every heading is dropped

Named by the diagnostic above, \@hangfrom is 179 of the 199 abandoned calls
across the 23 corpus documents that have any — 90%, and not a document's
malformed macro but our own substrate. 44 of them fall on one paper.

Real LaTeX's \@hangfrom takes ONE argument, the label (latex.ltx:12865);
the amsart family's second brace group is ordinary material, so the \par
that ends it is harmless (mathincs.cls:1177):

	\@hangfrom{\hskip #3\relax\@svsec}{\interlinepenalty\@m #8\par}

Ours takes that group as #2 — having no hanging indent, it has nothing
else to do with it — which makes the \par a runaway, and tex.web §392
abandons the call. The whole heading goes: number and title both. Without
the \long prefix the test's page comes out EMPTY.

Measured against a control built from the same base: abandoned calls
44→0 on 2401.13343 and 22→0 on 2408.04846, +4649 glyphs, no text lost.
Section numbers and whole subsection headings return; I diffed the text
layers and every word the diff called lost is still present, reflowed.

Five documents each change by a page, so the barometer moves 345→350 and
≤1pp 83→80. Three of the five were ALREADY longer than the reference while
missing their headings — 2401.13343 set 30 pages against 29, longer with
less content — so restoring the headings adds their height to a body whose
excess was being paid for by the loss. The other two shorten, which is page
breaking rearranging around a heading, not height. The deficit is now
visible instead of cancelled.

Co-Authored-By: Claude Opus 5 <[email protected]>

* engine: \long the emulation stubs whose real commands are \long

The other 20 of the 199 abandoned calls, each checked against the package
that defines the real command:

  \@subfloatopt/\@subfloatnoopt (13)  subfig.sty:350,354 are \long
  \subcaptionbox                      caption.sty:457 \newcommand (unstarred)
                                      and subcaption.sty:270 \long
  \@titlemand (1)                     latex.ltx:12747 \DeclareRobustCommand,
                                      unstarred, so \long (\@star@or@long,
                                      latex.ltx:1173)
  \@gobbleoptarg (2)                  \@footnotetext is \long (latex.ltx:13187);
                                      array.sty:273 rewrites likewise

\@authormand is the deliberate exception and keeps its short form:
latex.ltx:12748 declares \author with \DeclareRobustCommand*, and the STARRED
branch of \@star@or@long is \relax. A \par in an author block is a runaway in
real LaTeX too, so the 3 in the corpus are the documents' error, not ours.
A test pins that. \onlinecite (1) is revtex's, not ours.

The corpus page barometer does not move: 350 both sides, 27 exact, ≤1pp 80.
Five documents change and the raw glyph count falls by 10197 — which is the
FIX, not a regression. What disappears is TikZ source that the abandoned call
had pushed back and typeset AS TEXT:

  [] (end) -- (endbot) node[midway, right] \delta; [] (0,0.5) -- (5,0.5) ...

What appears is real: sub-caption labels ((b) (c) (d), (m) Bending problem),
table rows, and a section counter that was reading 1.1 where the reference has
2.1. A glyph census counts leaked source as content, so stopping a leak reads
as loss; the text-layer diff is what settles it.

Co-Authored-By: Claude Opus 5 <[email protected]>

---------

Co-authored-by: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Sep 9, 2026
…331)

Two halves of one mechanism, neither of which existed.

    \def\pagestyle#1{\@ifundefined{ps@#1}\undefinedpagestyle{\@nameuse{ps@#1}}}
                                                        latex.ltx:13326-13329
    \long\def\f@nch@pagestyle#1[#2]#3{… \@namedef{ps@#1}{…#3\relax} …}
                                                        fancyhdr.sty:438-450

\fancypagestyle was undefined, so its arguments were left in the input and
EXECUTED where they landed: a class's \fancyhead/\fancyfoot assignments reached
this engine's fields by ACCIDENT, and the style's name was typeset. acmart.cls:2589
declares standardpagestyle and firstpagestyle, and both names came out as body
text before \maketitle — on a two-column paper that lands ahead of the
\twocolumn[...], which starts a new column region, so it took a page of its own.

Now the definitions are stored under \ps@name and run when the style is SELECTED,
which is what makes a running head appear on the page that asked for it. On
2406.06585 page 2 began with body text and now reads

    ITERATED MAP IDENTIFICATION UCSB RMP AUG 2023

against the reference's

    UCSB RMP ITERATED MAP IDENTIFICATION AUG 2023

— the same content with the left and right fields transposed, which is a separate
question (this engine does not yet swap them by page parity).

I measured three variants of this in #318 and shipped none: giving \ps@name the
definitions changed nothing while the selection never ran them, and executing them
at declaration time bought Sigma by removing a real title block. Running them on
selection is the one the sources describe.

Measured over the 157-paper corpus: Sigma 343 -> 341 (-2), glyphs -5658.
2406.06585 goes 7 -> 6 pages against a reference of 6, so exact; 2408.04846 26 ->
25 against 24.

Eight papers are flagged. Each was checked: the deltas are at most 1% of the
paper's characters, they leave every other page byte-identical (2304.01951 changes
page 1 alone, 5647 -> 4752 characters, and pages 2-10 not at all), and the pages
they touch are the ones acmart fills with its own option junk — which is #306's
subject, not this one — or reflow around a head that now exists.

Co-authored-by: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Sep 11, 2026
amsthm lets a class style its own theorems by redefining \@BeginTheorem, and the
signature it publishes has a DELIMITED third parameter:

    \def\@BeginTheorem#1#2[#3]{…}

Journal classes copy it verbatim — oup's oupau.cls does. Called with no bracket
group, such a macro reads FORWARD through the document until it finds one.

In 2401.17012 a theorem swallowed the thirty lines after it, up to the
[X_\beta,X_\gamma] inside a formula. The formula came back from the maths layer
as one dropped equation the size of the rest of the paper ("texmath: unexpected
\"}\""), the stolen lines were typeset a second time as the theorem's note, and
the paragraph before them appeared twice on the page.

amsthm never calls it bare: \@thm goes through \@oparg (amsthm.sty:143), which
supplies [] when the document wrote no note. \newtheorem's generated macro now
does the same, and \@opargbegintheorem treats an empty note as no note so the
head still reads "Theorem 1." and not "Theorem 1 ()".

Also adds amsgen's \@ifempty / \@xifempty / \@ifnotempty, verbatim: amsthm's head
is built out of them, and undefined they were skipped with their arguments
typeset — which printed the head twice.

Corpus, 157 arXiv papers: Sigma|err| 338 -> 339 (+1, inside the ±3 the measure
can resolve), glyphs -1723 over three papers, each one a DUPLICATE removed:

  2401.17012  -812  a paragraph that was set twice, and a theorem head carrying
                    thirty stolen lines as its note; the reference's order
                    (…Vessiot and Guldberg… then Theorem 2.2) is now ours
  2401.13343  -569  a duplicated author line in the title block
  2407.18384  -427  "Definition 1 ()." becomes "Definition 1."

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
tannevaled added a commit that referenced this pull request Sep 23, 2026
A file spec takes TWO optional arguments, options and a DATE:

    \@onefilewithoptions#1[#2][#3]#4        latex.ltx:13735

The date is how a package states the version it needs. jabbrv.sty writes

    \RequirePackage{kvoptions}[2006/08/17]

and we read only the options, so the date was typeset. Every document that loads
jabbrv opened on a page carrying "[2006/08/17]" and nothing else, its title
pushed to page 2 — visible on the corpus's 2408.02845 (wlscirep), whose class
requires jabbrv.

The lookahead uses getNext, NOT getXToken. LaTeX's own is \@ifnextchar, which is
\futurelet and expands nothing; expanding runs whatever follows the load before
the package is registered, and the first draft of this made

    \usepackage{p}\@ifpackageloaded{p}{…}{…}

answer "not loaded" — two existing tests caught it, which is the whole point of
their being there.

MEASURED: Sigma 299 -> 300 over the 154-paper corpus, inside the +-3 this corpus
can resolve, and a leaked version date leaves page 1.

A bracket that is NOT a date — one opening a paragraph after a blank line —
still survives, in both engines: the \par stops the lookahead. Pinned.

Co-authored-by: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Sep 24, 2026
…ckwards (#409)

* \resizebox* printed its own arguments onto the page

The star is the whole difference between the two forms, and it is one word of
graphics.sty:539-541:

    \protected\def\resizebox{%
      \leavevmode
      \@ifstar{\Gscale@@box\totalheight}{\Gscale@@box\height}}

\resizebox sizes the box by its HEIGHT above the baseline, \resizebox* by its
TOTAL height, depth included. Everything else is shared.

The star was never consumed, so neither dimension parsed and the source reached
the page as text. `Y\resizebox*{30mm}{!}{CONTENU}Y` set

    Y*30mm!CONTENUY

with the content unscaled. One corpus paper wraps every one of its four figures
this way and printed "*45mm!", "*100mm!" and "*65mm!" into them, each around a
tikzpicture that then went unscaled.

20 of the 154 corpus papers use \resizebox, 111 times, 4 of them starred.

Co-Authored-By: Claude Opus 5 <[email protected]>

* \rule's lift was added to its height instead of crossing the baseline

The lift of \rule[lift]{width}{height} moves the rule ACROSS the baseline; it does
not make it taller. latex.ltx:11900-11907 says which dimension takes it:

    \def\@rule[#1]#2#3{%
      \leavevmode
      \hbox{%
        \setlength\@tempdima{#1}%   lift
        \setlength\@tempdimb{#2}%   width
        \setlength\@tempdimc{#3}%   height
        \advance\@tempdimc\@tempdima
        \vrule\@width\@tempdimb\@height\@tempdimc\@Depth-\@tempdima}}

so height = #3 + lift and depth = -lift. Both signs were the wrong way round here.

Asked directly, tectonic answers:

    \rule[2pt]{3pt}{6pt}    ht=8.0pt  dp=0.0pt
    \rule[-2pt]{3pt}{6pt}   ht=4.0pt  dp=2.0pt
    \rule{3pt}{6pt}         ht=6.0pt  dp=0.0pt

and this engine now answers the same three. Before, a negative lift — the only
kind that does anything visible — was ADDED to the height and asked for a negative
depth the packer clamped to zero: \rule[-2mm]{3mm}{6mm} packed 8mm tall and 0mm
deep. One corpus paper writes \rule[-\textheight/2]{1ex}{\textheight}, meant to
straddle the baseline by half a page each way; it packed one and a half pages
above it. 4 of the 154 papers use a non-zero lift, 21 times.

A lift of zero, which is what \rule{w}{h} supplies, is unaffected either way, so
nothing else in the corpus moves.

TestRuleLift demanded the inversion outright — height 4pt and depth 2pt for a
+2pt lift — and so pinned it in place. It now asks tectonic's answer, and checks
the enclosing hbox clamps the negative depth the way TeX's hpack does (tex.web
§649).

Co-Authored-By: Claude Opus 5 <[email protected]>

---------

Co-authored-by: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Sep 25, 2026
\@setfontsize#1#2#3 states a size (#2) and a leading (#3). The leading reached
\gotex@notefontsize only inside the \ifx#1\normalsize guard, so nine of the ten
size commands stated a skip that went nowhere.

latex.ltx:8533 \set@fontsize sets both from the one call; only
\gotex@classnormalsize, which records what the class calls normal and is the
denominator every other size is scaled against, belongs under that guard.

\the\baselineskip, tectonic against this engine:

                    tectonic   before    after
  \normalsize          12.0     12.0     12.0
  \small               11.0     12.0     11.0
  \footnotesize         9.5     12.0      9.5
  \Large               18.0     12.0     18.0

Each reference value is exactly the third argument of that size's \@setfontsize
call in the class size file, which is what makes the locus certain.

It is not only the register — the engine acts on \baselineskip, so a frozen
register was a frozen leading. Distance between two consecutive lines:

                       tectonic   before    after
  \normalsize             11.96    12.00    12.00
  \footnotesize            9.46    12.00     9.50
  \Large                  17.93    12.00    18.00
  back to \normalsize     11.96    12.00    12.00

\normalsize is the CONTROL and was already right, which is why this never looked
like a defect: body text was correct and only the size-switched blocks —
captions, abstracts, table bodies, and in several classes the whole bibliography
— were not. The residual +0.04pt is this engine's sp rounding and the control
carries it too.

\f@baselineskip had to become scoped with it. It is scoped in LaTeX (\set@fontsize
\edef's it inside whatever group is open), and baselineStretchFactor recovers the
line-spacing factor as the RATIO baselineskip/baseBaselineskip, so a
baseBaselineskip left behind by a closing brace reads as a \linespread the
document never asked for. Measured with the fix in and the scoping out, \Large
after a \footnotesize group comes out 22.73pt instead of 17.93 — 18 x (12/9.5),
compounding at every later switch. \linespread{1.5} is right in all three places
it is read: 18.00, 14.25 inside \footnotesize, 18.00 again on the way out.

One existing assertion changed rather than being accommodated. "another size
command is ignored" pinned \baselineskip NOT moving for a non-\normalsize switch,
which is the defect and not a requirement — the reference gives \small an 11pt
skip. What the \ifx guard legitimately protects went unasserted while it also
held the leading back, so TestSetfontsizeOnlyNormalsizeRestatesTheClassSize now
covers it, verified by removing the guard: a \small then moves the class size
reference from 10 to 9 and puts the whole ladder on a 9pt base.

Co-Authored-By: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Sep 25, 2026
\@setfontsize#1#2#3 states a size (#2) and a leading (#3). The leading reached
\gotex@notefontsize only inside the \ifx#1\normalsize guard, so nine of the ten
size commands stated a skip that went nowhere.

latex.ltx:8533 \set@fontsize sets both from the one call; only
\gotex@classnormalsize, which records what the class calls normal and is the
denominator every other size is scaled against, belongs under that guard.

\the\baselineskip, tectonic against this engine:

                    tectonic   before    after
  \normalsize          12.0     12.0     12.0
  \small               11.0     12.0     11.0
  \footnotesize         9.5     12.0      9.5
  \Large               18.0     12.0     18.0

Each reference value is exactly the third argument of that size's \@setfontsize
call in the class size file, which is what makes the locus certain.

It is not only the register — the engine acts on \baselineskip, so a frozen
register was a frozen leading. Distance between two consecutive lines:

                       tectonic   before    after
  \normalsize             11.96    12.00    12.00
  \footnotesize            9.46    12.00     9.50
  \Large                  17.93    12.00    18.00
  back to \normalsize     11.96    12.00    12.00

\normalsize is the CONTROL and was already right, which is why this never looked
like a defect: body text was correct and only the size-switched blocks —
captions, abstracts, table bodies, and in several classes the whole bibliography
— were not. The residual +0.04pt is this engine's sp rounding and the control
carries it too.

\f@baselineskip had to become scoped with it. It is scoped in LaTeX (\set@fontsize
\edef's it inside whatever group is open), and baselineStretchFactor recovers the
line-spacing factor as the RATIO baselineskip/baseBaselineskip, so a
baseBaselineskip left behind by a closing brace reads as a \linespread the
document never asked for. Measured with the fix in and the scoping out, \Large
after a \footnotesize group comes out 22.73pt instead of 17.93 — 18 x (12/9.5),
compounding at every later switch. \linespread{1.5} is right in all three places
it is read: 18.00, 14.25 inside \footnotesize, 18.00 again on the way out.

One existing assertion changed rather than being accommodated. "another size
command is ignored" pinned \baselineskip NOT moving for a non-\normalsize switch,
which is the defect and not a requirement — the reference gives \small an 11pt
skip. What the \ifx guard legitimately protects went unasserted while it also
held the leading back, so TestSetfontsizeOnlyNormalsizeRestatesTheClassSize now
covers it, verified by removing the guard: a \small then moves the class size
reference from 10 to 9 and puts the whole ladder on a 9pt base.

Co-authored-by: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Sep 26, 2026
ltdefns.dtx:

	\long\def\@ifnextchar#1#2#3{\let\reserved@d=#1
	  \def\reserved@a{#2}\def\reserved@b{#3}\futurelet\@let@token\@ifnch}

\let\reserved@d=#1 takes #1 as an UNDELIMITED ARGUMENT, so a brace group around the
target is stripped and \@ifnextchar{*}{A}{B} tests for a star exactly as
\@ifnextchar*{A}{B} does. This primitive read it with one getNext, which took the
BRACE as the target — after which the two branches were read one token late, BOTH
were emitted, and the star was typeset.

Judged against tectonic 0.17.0:

	\def\tb{\@ifnextchar{*}{YES}{NO}}   A\tb* B\tb x C
	\def\tn{\@ifnextchar*{YES}{NO}}     D\tn* E\tn y F

	reference   braced: AYES* BNOx C          bare: DYES* ENOy F
	before      braced: A*YESNO* B*YESNOx C   bare: DYES* ENOy F
	after       braced: AYES* BNOx C          bare: DYES* ENOy F

Only the braced form was wrong, and every earlier witness used a bare target — which
is how it survived. A bare control sequence (\@ifnextchar\bgroup) and a bare
character (\@ifnextchar[) both arrive as a one-token argument and are unchanged.

It is not a corner case. xkeyval reaches it through xkvutils' \@ifnextcharacter,
whose FIRST branch has a braced target and is taken whenever the next token is a
brace — \setkeys{fam}{…}, the common case. Every \setkeys printed "*+" and left two
groups open. On the 8-line witness of #306:

	\usepackage{xkeyval}
	\define@key{fam}{name}{[got #1]}
	\setkeys{fam}{name=VALUE}

	before  *+            after  [got VALUE]    reference  [got VALUE]

and on corpus paper 2407.13726 (acmart [acmsmall,authorversion,nonacm,screen],
reference 27 pages), with the real xkeyval on GOTEX_TEXMF:

	before  1 page,  9 undefined, 41 argument grabs abandoned, 4 groups open
	after   26 pages, 21 undefined, none abandoned, no group left open

Measured on the DEFAULT configuration, clean list of 154, against deb1e54:

	Sigma|err| 328 -> 328 (+0), glyphs +0, 0 papers moved

Neutral by default because nothing in the default path writes a braced target — the
xkeyval that does is not embedded yet (see #306, and branch fix/filelist for the
three kernel names it also needs).

TestIfnextcharTargetIsAnArgumentNotAToken pins all four combinations and fails on
the parent with "ranNO branch ALSO ran — both were emitted", on the braced cases
only.

Co-authored-by: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Sep 26, 2026
Both read straight past it. color.sty:88-90 and 103-104 (xcolor.sty:711 and 758-759
are the same):

	\DeclareRobustCommand\color{\@ifnextchar[\@undeclaredcolor\@declaredcolor}
	\def\@undeclaredcolor[#1]#2{…\csname color@#1\endcsname\current@color{#2}…}
	\protected\def\textcolor#1#{\@textcolor{#1}}
	\def\@textcolor#1#2#3{\protect\leavevmode{\color#1{#2}#3}}

\textcolor's parameter text is "#1#" — delimited by the next brace — so the bracket,
if any, lands in #1 and the name in #2. Taking two plain arguments bound #1=[HTML]
and #2={FF0000} and left the TEXT unconsumed. For \color, readBraceName saw "["
where it wanted "{", backed the token up and returned empty: the colour was not set
AND the spec was typeset.

parseColorSpec already knew every model the reference does (rgb, RGB, gray, HTML,
cmyk) — it was reachable only through \definecolor.

Judged against tectonic 0.17.0, which renders "A ROUGEB C VERT D E BLEU F G RGBH":

	before  A [HTML]FF0000ROUGE B C HTML]00FF00VERT D E BLEU F G [rgb]1,0,0RGB H
	after   A ROUGE B C VERT D E BLEU F G RGB H

Measured, clean list of 154, against 6953499:

	Sigma|err| 328 -> 324 (-4), glyphs -14243, 9 papers moved

and THREE of them land exactly: 2304.05592 (21->20 of 20), 2402.04392 (9->8 of 8),
2402.04684 (10->9 of 9). 2405.18549 goes 42->41 of 37 and 2407.09954 28->30 of 31.

abpair flags six as losing content; every one is the SPEC no longer being typeset.
Judged the only way that answers it — are the lost WORDS in the paper's reference PDF:

	paper        words lost  of them in the reference   sample
	2304.05592          284                        4    rgb]0.37,0.37,0.37#
	2407.13726          181                        3    [HTML]000000sparsity
	2405.18549          111                        3    ${w_R}$
	2402.04711          113                        -    (no reference PDF)
	2111.13456           38                        0    c(\partial_{t}p…
	2311.09365           17                        0    [rgb]0,0,0

2304.05592's four are "11", "13", "14" and "high-dimensional" — page numbers, and one
word that was GLUED to a spec ("rgb]…high-dimensional") and now stands on its own. Its
word count moves only 8217 -> 8197 while its glyphs move -8292: the specs were inside
words, and removing them shortens words without removing text.

Known and deliberately NOT in this change: the reference's \@undeclaredcolor and
\@declaredcolor both end with \ignorespaces and ours do not, so "\color{black} B"
keeps a space the reference eats ("ROUGE B" against "ROUGEB"). That predates this and
touches every \color in the corpus, so it wants its own measurement. \leavevmode is
left out of \textcolor for the same reason.

TestColorTakesAnOptionalModel pins all four forms and fails on the parent with five
specs on the page.

Co-authored-by: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Sep 26, 2026
… from #452 (#454)

#452 gave \textcolor the reference's own parameter text,
\protected\def\textcolor#1#{\@textcolor{#1}} (color.sty:103, xcolor.sty:758), whose
first argument is delimited by the next BRACE. That is right for TeX and wrong here: the
maths layer works on a SOURCE STRING, and renderMathResolvingMacros expands a macro by
matching its parameter text against TEXT. It cannot match a brace-delimited parameter.

	\newcommand{\W}{\ensuremath{\textcolor{darkgreen}{\boldsymbol{w}_R}}}

expanded to "{arkgreen{" — the backslash and the colour name's first letter eaten — and
go-tex/math refused it with "missing }". 52 equations on corpus paper 2405.18549 and 86
over five papers, NONE of them dropped before #452.

An \@ifnextbracket dispatcher fails the same way for the same reason: it has to LOOK at
the next token, which a string expander cannot do. It reached the maths layer as
\@ifnextbracket and dropped the equation under that name instead. Both were tried.

A PRIMITIVE is the answer, and not by accident: expandMacroInMathSource declines a
primitive, so the source falls through to stripMathColor, which already knows the
command and its optional model (math.go, "textcolor": {2, 1}) and strips it while
KEEPING the content — an equation set in the surrounding colour rather than dropped.

In text it rebuilds the reference's own body, {\color#1{#2}#3} (color.sty:104), and
pushes it for the mouth to read: the group is TeX's. Opening it with e.beginGroup and
closing it by pushing \endgroup instead left the brace bookkeeping one deep and every
\textcolor raised "Missing } inserted" — four tests caught that.

Measured, clean list of 154, against 7c6e838:

	Sigma|err| 324 -> 325 (+1), glyphs +3539, 0 papers losing content

	2111.13456  ref 29   35 -> 34
	2402.04711  ref 198  180 -> 181
	2405.18549  ref 37   41 -> 42
	2407.09954  ref 31   30 -> 28

+1 on Sigma for 3539 glyphs of mathematics that the reference has and we were dropping.
A restored equation moves a page count in EITHER direction (measure/TOOLS.md); the four
papers are back exactly where they stood before #452.

## What let a merged change lose 86 equations

The A/B did not see it. Sigma went DOWN by 4 and the glyph delta showed 2416 fewer on
2405.18549, which I read as the colour specs #452 stops typesetting — and part of it
was. The rest was the equations. One of the "garbage" words I cleared it on was
"${w_R}$", which is the SYMBOL.

What saw it was the per-channel census (campaign.py): "$math$ texmath: missing }" went
from absent to 86 in five papers. A page count cannot see an equation, so a change to a
colour command has to be measured on the equation channel too.

TestTextcolorInMathsKeepsTheEquation pins all three shapes — direct, through a macro as
the corpus writes it, and with a model — and is the test that should have existed before
#452.

Co-authored-by: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Oct 3, 2026
…t the name (#530)

cleveref's other interface: \crefformat{type}{template} replaces the whole
rendering, name included, with a three-parameter template — #1 the number, #2 a
prefix and #3 a suffix, which are its hyperlink wrappers and are empty here. It
is applied through cref@<type>@Format and never consults the name
(cleveref.sty:543-549), so a format wins over every naming tier.

One corpus paper in 154 uses it, twice: 2406.01525 writes

	\crefformat{section}{#2\S#1#3}
	\Crefformat{section}{#2\S#1#3}

and its reference prints "§" 73 times where the engine printed "Section" 52
times and "§" none. Measured on that paper directly, after: § 74 against 73,
"Section" 0 against 0.

Three things the oracle decided rather than the source, each of which had been
guessed wrong first:

  - a template read with grabGroup keeps "#1" as TWO tokens, a catParam '#' and
    the digit, where a \def body folds them into one. The first substitution
    looked only for the folded form and printed "#2§#1#3" on the page.
  - a one-sided \crefformat cross-fills the other case by shifting the FIRST
    LETTER only: {fig.~#2#1#3} makes \Cref print "Fig. 1", not "FIG. 1" from a
    whole-word \MakeUppercase and not the default "Figure 1". cleveref's
    \@crefformat (cleveref.sty:1886-1910) wraps the copy in \MakeUppercase with
    an UNBRACED argument, which is the same first-letter trick \@crefname uses.
  - a subsection with no format of its own follows the SECTION's — the same
    fallback that makes cleveref's default NAME for a subsection "section".
    Asked both ways: \crefname{subsection}{subsec.} IS honoured, so the type
    really is `subsection` and this is a fallback, not an alias.

Several keys still go through the naming path: that is \crefmultiformat in
cleveref, which no corpus paper uses.

Measured by channel over the 16 papers that use \cref:

	Σ|deviation|   581 -> 528    3 rows toward the reference, 1 away

The one row away is "Definition" 32 -> 31 against a reference 41, a drift of one
from reflow.

⛔ AND IT DOES NOT RECOVER THE PAGE. #527 and #528 both said this was "the whole
of 2406.01525's remaining deficit"; that prediction is measured false. The paper
stays at 37 pages against a reference 35 — Σ|deviation| 339 and exact pagination
37 are unchanged corpus-wide. Its text ratio falls 98.4% -> 97.5% because "§" is
three characters and the corpus text census counts words of five or more, so
replacing 52 wrong "Section"s with the right symbol reads there as a loss. What
keeps that paper two pages long is something else, still unidentified.

Co-authored-by: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Oct 4, 2026
…lias was built anyway (#547)

latex.ltx's \@othm tests \@ifundefined{c@#2} and errors — "No theorem environment #2
defined" — because that counter does not exist yet, so real LaTeX numbers nothing and
carries on. Here the alias was built regardless:

	\the<env> := \the<shared>, which when shared == env is \the<env> again

a self-referential macro the engine then spun 400 times into the runaway guard. The
test's failure message shows it at the token level: [macro:->\thecorollary ].

Two corpus papers write it, one directly and one through a wrapper of its own:

	\newtheorem{corollary}[corollary]{Corollary}        2607.21390   3 ->  11 pages
	\newtheorem{#1vArIAblE}[#1vArIAblE]{#3}             2606.14675   2 ->  37 pages

open groups 3 -> 0 and 4 -> 0, runaway gone in both.

Dropping the self-share leaves the environment a counter of its own, which is what the
code already does when no [shared] is given at all. The second test is there because the
cure must not break what [shared] is FOR: \newtheorem{example}[theorem] must still give
\theexample = \thetheorem, which carries the section (latex.ltx:12728).

Co-authored-by: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Oct 22, 2026
…sts (#636, #629) (#642)

caption3.sty:237-243:

	\newif\ifcaptionsetup@star
	\newcommand*\captionsetup{\caption@teststar@\@captionsetup\@gobble\@Firstofone}
	\newcommand*\@captionsetup[1]{\captionsetup@startrue#1\captionsetup@starfalse…}

All the star does is raise that flag, and the flag's ONE use is to suppress a
warning: caption.sty:319 reads \ifcaptionsetup@star\else\@nameuse{caption@#1type@
warning}\fi. Nothing it typesets changes, so the star is consumed and nothing else
here does.

Unread, the star WAS the argument: scanBracketList met "*" instead of "[", so the key
list was never read and the whole lot went on the page.

caption3.sty:696-706 for the second half:

	\newcommand*\DeclareCaptionFormat{\caption@teststar\caption@declareformat…}
	\newcommand*\caption@declareformat[2]{\@dblarg{\caption@@declareformat#1{#2}}}
	\long\def\caption@@declareformat#1#2[#3]#4{…}

— an optional star, the name, an OPTIONAL single-line variant that \@dblarg defaults
to the mandatory one, and the body. Undefined, it left all of that behind.

paper.cls (PNAS) writes both, four lines apart:

	\DeclareCaptionFormat{pnasformat}{\normalfont\sffamily…#1#2#3}   % :154
	\captionsetup*{format=pnasformat}                                % :155

and page 1 of 2310.11517 read "*format=pnasformat" in its body text. 29 corpus papers
write \captionsetup* (#636).

Caption FORMATS are not modelled here — the caption head goes through \fnum@<type>,
see doCaptionsetup — so the declaration is consumed and nothing is kept. What matters
is that it stops reaching the page.

⛔ The test reads through captionHead, not pageOf: a float's content is DEFERRED and
never reaches the main vertical list, so pageOf comes back empty for BOTH forms — a
comparison of nothing with nothing, which is how this test first "passed". And all
four spellings of \DeclareCaptionFormat's grammar are exercised, because a dispatcher
that reads three and leaks the fourth looks exactly like one that works. Run against
the unfixed files, both tests fail and print the leaked text.

⚠ This does NOT fix 2310.11517's author line, which is still 1787.88pt wide. That is a
separate cause and stays open on #629.

Co-authored-by: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Nov 7, 2026
#726 gave \pagestyle{headings} its band, its folio and its rule, and #426's own
witness still came out with an EMPTY head. The cause is the last link, and it is
a name:

  \leftmark / \rightmark read \gotex@leftmark / \gotex@rightmark, a PRIVATE pair
  that only this engine's own \markboth ever wrote.

A class may bring its own \markboth, and amsart.cls does — one of the four
classes this engine advertises running (texmf/amsart.cls:335-340):

  \def\markboth#1#2{\begingroup
    \@temptokena{{#1}{#2}}\xdef\@theMark{\the\@temptokena}%
    \mark{\the\@temptokena}\endgroup …}

It writes \@theMark, the kernel's name (ltpage.dtx:355 \def\@theMark{{}{}}), and
touches no private pair. Every other link already worked: \ps@headings does
\let\@mkboth\markboth (amsart.cls:318), amsart calls
\@mkboth{\@nx\shortauthors}{\@nx\shorttitle} (:622), the mark was set. Only the
read was looking elsewhere.

So the pair moves to \@theMark and the accessors become the kernel's own
(ltpage.dtx:167-174, 341-342, 356-357):

  \let\@leftmark\@FirstOfTwo              \let\@rightmark\@secondoftwo
  \def\@theMark{{}{}}
  \def\markboth#1#2{\protected@xdef\@theMark{{#1}{#2}}}
  \def\@markright#1#2#3{\@temptokena{#1}%
    \protected@xdef\@theMark{{\the\@temptokena}{#3}}}
  \def\markright#1{\expandafter\@markright\@theMark{#1}}
  \def\leftmark{\expandafter\@leftmark\@theMark\@empty\@empty}
  \def\rightmark{\expandafter\@rightmark\@theMark\@empty\@empty}

\markright keeps the LEFT half, which is why the kernel routes it through
\@markright rather than assigning both — and \ps@headings's \sectionmark IS a
\markright, so the wrong shape would wipe half the head at every section. The
two \@empty are the kernel's guard for a pair never set.

⛔ WHAT WAS WRONG WITH THE TESTS, not just with the code. Two tests probed
\gotex@rightmark — the STORAGE — so they were green for every document whose
class brings its own \markboth, which is the only case that was broken. They now
probe \rightmark, the name a page style reads. Two tests added:

  - a class's own \markboth (amsart's idiom verbatim in shape) must reach
    \leftmark/\rightmark — the test #426 needed;
  - \markright keeps the left half.

Run against the previous commit, which is the control a new test needs or it
proves nothing, they do NOT both fail — and the difference matters:

  class's own \markboth   FAILS, "[|]" — both halves empty. #426 reproduced.
  \markright keeps left   PASSES. The old private pair kept the left too,
                          since \markright wrote only \gotex@rightmark.

So the second one is not a regression test for this change; it is a guard that
the new \@markright shape — which destructures the pair and rebuilds it — did
not lose what the simpler assignment got right. Keeping it, labelled for what it
is, rather than letting it be counted as evidence.

Still NOT done, and unchanged by this: the pair is the single live one, where
the kernel reads \botmark and \firstmark so a head shows the mark of THAT page
(#727). amsart is immune to that difference by construction — it \@Gobbles
\sectionmark and friends (amsart.cls:344-346), so its head is set once from the
authors and the short title.

Co-Authored-By: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Nov 7, 2026
#726 gave \pagestyle{headings} its band, its folio and its rule, and #426's own
witness still came out with an EMPTY head. The cause is the last link, and it is
a name:

  \leftmark / \rightmark read \gotex@leftmark / \gotex@rightmark, a PRIVATE pair
  that only this engine's own \markboth ever wrote.

A class may bring its own \markboth, and amsart.cls does — one of the four
classes this engine advertises running (texmf/amsart.cls:335-340):

  \def\markboth#1#2{\begingroup
    \@temptokena{{#1}{#2}}\xdef\@theMark{\the\@temptokena}%
    \mark{\the\@temptokena}\endgroup …}

It writes \@theMark, the kernel's name (ltpage.dtx:355 \def\@theMark{{}{}}), and
touches no private pair. Every other link already worked: \ps@headings does
\let\@mkboth\markboth (amsart.cls:318), amsart calls
\@mkboth{\@nx\shortauthors}{\@nx\shorttitle} (:622), the mark was set. Only the
read was looking elsewhere.

So the pair moves to \@theMark and the accessors become the kernel's own
(ltpage.dtx:167-174, 341-342, 356-357):

  \let\@leftmark\@FirstOfTwo              \let\@rightmark\@secondoftwo
  \def\@theMark{{}{}}
  \def\markboth#1#2{\protected@xdef\@theMark{{#1}{#2}}}
  \def\@markright#1#2#3{\@temptokena{#1}%
    \protected@xdef\@theMark{{\the\@temptokena}{#3}}}
  \def\markright#1{\expandafter\@markright\@theMark{#1}}
  \def\leftmark{\expandafter\@leftmark\@theMark\@empty\@empty}
  \def\rightmark{\expandafter\@rightmark\@theMark\@empty\@empty}

\markright keeps the LEFT half, which is why the kernel routes it through
\@markright rather than assigning both — and \ps@headings's \sectionmark IS a
\markright, so the wrong shape would wipe half the head at every section. The
two \@empty are the kernel's guard for a pair never set.

⛔ WHAT WAS WRONG WITH THE TESTS, not just with the code. Two tests probed
\gotex@rightmark — the STORAGE — so they were green for every document whose
class brings its own \markboth, which is the only case that was broken. They now
probe \rightmark, the name a page style reads. Two tests added:

  - a class's own \markboth (amsart's idiom verbatim in shape) must reach
    \leftmark/\rightmark — the test #426 needed;
  - \markright keeps the left half.

Run against the previous commit, which is the control a new test needs or it
proves nothing, they do NOT both fail — and the difference matters:

  class's own \markboth   FAILS, "[|]" — both halves empty. #426 reproduced.
  \markright keeps left   PASSES. The old private pair kept the left too,
                          since \markright wrote only \gotex@rightmark.

So the second one is not a regression test for this change; it is a guard that
the new \@markright shape — which destructures the pair and rebuilds it — did
not lose what the simpler assignment got right. Keeping it, labelled for what it
is, rather than letting it be counted as evidence.

Still NOT done, and unchanged by this: the pair is the single live one, where
the kernel reads \botmark and \firstmark so a head shows the mark of THAT page
(#727). amsart is immune to that difference by construction — it \@Gobbles
\sectionmark and friends (amsart.cls:344-346), so its head is set once from the
authors and the short title.

Co-Authored-By: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Nov 7, 2026
… (#728)

#726 gave \pagestyle{headings} its band, its folio and its rule, and #426's own
witness still came out with an EMPTY head. The cause is the last link, and it is
a name:

  \leftmark / \rightmark read \gotex@leftmark / \gotex@rightmark, a PRIVATE pair
  that only this engine's own \markboth ever wrote.

A class may bring its own \markboth, and amsart.cls does — one of the four
classes this engine advertises running (texmf/amsart.cls:335-340):

  \def\markboth#1#2{\begingroup
    \@temptokena{{#1}{#2}}\xdef\@theMark{\the\@temptokena}%
    \mark{\the\@temptokena}\endgroup …}

It writes \@theMark, the kernel's name (ltpage.dtx:355 \def\@theMark{{}{}}), and
touches no private pair. Every other link already worked: \ps@headings does
\let\@mkboth\markboth (amsart.cls:318), amsart calls
\@mkboth{\@nx\shortauthors}{\@nx\shorttitle} (:622), the mark was set. Only the
read was looking elsewhere.

So the pair moves to \@theMark and the accessors become the kernel's own
(ltpage.dtx:167-174, 341-342, 356-357):

  \let\@leftmark\@FirstOfTwo              \let\@rightmark\@secondoftwo
  \def\@theMark{{}{}}
  \def\markboth#1#2{\protected@xdef\@theMark{{#1}{#2}}}
  \def\@markright#1#2#3{\@temptokena{#1}%
    \protected@xdef\@theMark{{\the\@temptokena}{#3}}}
  \def\markright#1{\expandafter\@markright\@theMark{#1}}
  \def\leftmark{\expandafter\@leftmark\@theMark\@empty\@empty}
  \def\rightmark{\expandafter\@rightmark\@theMark\@empty\@empty}

\markright keeps the LEFT half, which is why the kernel routes it through
\@markright rather than assigning both — and \ps@headings's \sectionmark IS a
\markright, so the wrong shape would wipe half the head at every section. The
two \@empty are the kernel's guard for a pair never set.

⛔ WHAT WAS WRONG WITH THE TESTS, not just with the code. Two tests probed
\gotex@rightmark — the STORAGE — so they were green for every document whose
class brings its own \markboth, which is the only case that was broken. They now
probe \rightmark, the name a page style reads. Two tests added:

  - a class's own \markboth (amsart's idiom verbatim in shape) must reach
    \leftmark/\rightmark — the test #426 needed;
  - \markright keeps the left half.

Run against the previous commit, which is the control a new test needs or it
proves nothing, they do NOT both fail — and the difference matters:

  class's own \markboth   FAILS, "[|]" — both halves empty. #426 reproduced.
  \markright keeps left   PASSES. The old private pair kept the left too,
                          since \markright wrote only \gotex@rightmark.

So the second one is not a regression test for this change; it is a guard that
the new \@markright shape — which destructures the pair and rebuilds it — did
not lose what the simpler assignment got right. Keeping it, labelled for what it
is, rather than letting it be counted as evidence.

Still NOT done, and unchanged by this: the pair is the single live one, where
the kernel reads \botmark and \firstmark so a head shows the mark of THAT page
(#727). amsart is immune to that difference by construction — it \@Gobbles
\sectionmark and friends (amsart.cls:344-346), so its head is set once from the
authors and the short title.

Co-authored-by: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Nov 7, 2026
#729)

* the running mark pair lives under the name the classes write, \@theMark

#726 gave \pagestyle{headings} its band, its folio and its rule, and #426's own
witness still came out with an EMPTY head. The cause is the last link, and it is
a name:

  \leftmark / \rightmark read \gotex@leftmark / \gotex@rightmark, a PRIVATE pair
  that only this engine's own \markboth ever wrote.

A class may bring its own \markboth, and amsart.cls does — one of the four
classes this engine advertises running (texmf/amsart.cls:335-340):

  \def\markboth#1#2{\begingroup
    \@temptokena{{#1}{#2}}\xdef\@theMark{\the\@temptokena}%
    \mark{\the\@temptokena}\endgroup …}

It writes \@theMark, the kernel's name (ltpage.dtx:355 \def\@theMark{{}{}}), and
touches no private pair. Every other link already worked: \ps@headings does
\let\@mkboth\markboth (amsart.cls:318), amsart calls
\@mkboth{\@nx\shortauthors}{\@nx\shorttitle} (:622), the mark was set. Only the
read was looking elsewhere.

So the pair moves to \@theMark and the accessors become the kernel's own
(ltpage.dtx:167-174, 341-342, 356-357):

  \let\@leftmark\@FirstOfTwo              \let\@rightmark\@secondoftwo
  \def\@theMark{{}{}}
  \def\markboth#1#2{\protected@xdef\@theMark{{#1}{#2}}}
  \def\@markright#1#2#3{\@temptokena{#1}%
    \protected@xdef\@theMark{{\the\@temptokena}{#3}}}
  \def\markright#1{\expandafter\@markright\@theMark{#1}}
  \def\leftmark{\expandafter\@leftmark\@theMark\@empty\@empty}
  \def\rightmark{\expandafter\@rightmark\@theMark\@empty\@empty}

\markright keeps the LEFT half, which is why the kernel routes it through
\@markright rather than assigning both — and \ps@headings's \sectionmark IS a
\markright, so the wrong shape would wipe half the head at every section. The
two \@empty are the kernel's guard for a pair never set.

⛔ WHAT WAS WRONG WITH THE TESTS, not just with the code. Two tests probed
\gotex@rightmark — the STORAGE — so they were green for every document whose
class brings its own \markboth, which is the only case that was broken. They now
probe \rightmark, the name a page style reads. Two tests added:

  - a class's own \markboth (amsart's idiom verbatim in shape) must reach
    \leftmark/\rightmark — the test #426 needed;
  - \markright keeps the left half.

Run against the previous commit, which is the control a new test needs or it
proves nothing, they do NOT both fail — and the difference matters:

  class's own \markboth   FAILS, "[|]" — both halves empty. #426 reproduced.
  \markright keeps left   PASSES. The old private pair kept the left too,
                          since \markright wrote only \gotex@rightmark.

So the second one is not a regression test for this change; it is a guard that
the new \@markright shape — which destructures the pair and rebuilds it — did
not lose what the simpler assignment got right. Keeping it, labelled for what it
is, rather than letting it be counted as evidence.

Still NOT done, and unchanged by this: the pair is the single live one, where
the kernel reads \botmark and \firstmark so a head shows the mark of THAT page
(#727). amsart is immune to that difference by construction — it \@Gobbles
\sectionmark and friends (amsart.cls:344-346), so its head is set once from the
authors and the short title.

Co-Authored-By: Claude Opus 5 <[email protected]>

* marks travel with page breaking: \mark, \topmark, \firstmark, \botmark

#426's witness has its running head. It took four fixes, three of which were
right and insufficient, and the fourth is one line that threw the mark away.

  2111.13456 page 2, before:  y=98.99  "2"
                      after:  y=99.17  "A POSTERIORI ESTIMATION FOR
                                        MULTIPLE-NETWORK POROELASTICITY"  "2"

⛔⛔ THE LINE. amssubstrate.go carried `\def\mark#1{}` — a stub that DISCARDS its
argument — with the reason it stated: "page marks feed running heads the engine
does not build; drop the mark". True when written. It then survived every fix to
the chain above it: the band and the folio (#726), the page-style dispatch, and
the pair's name (#728). Each of those was correct, and each left the head empty,
because the mark was being dropped one layer below all of them.

A stub that discards its argument is the one shape no channel can see: the
document says what it wants, the engine says nothing, the suite stays green, and
the loss appears only as ink that is not on the page. The measurement harness has
a section about exactly this trap ("the blind spot no channel has"), and it still
cost 27 of the 128 corpus papers with a reference their head, through three
rounds of fixing the wrong layer.

WHAT IS IMPLEMENTED, from tex.web:

  \mark{…}  a node on the vertical list (markNode), the argument EXPANDED at
            mark time — scan_toks(false,true). Not a detail: amsart writes
            \@temptokena{{#1}{#2}}…\mark{\the\@temptokena}, so an unexpanded
            mark would store "\the\@temptokena" and the head would read \the.
            It travels like pageStyleNode, for the same reason: at mark time
            nothing knows which page it lands on.

  \topmark / \firstmark / \botmark  republished before each page's head is
            built, from §1012's arithmetic (:19718-19729, :19782-19789):

              if bot<>null then top:=bot; first:=null
              walking the page: if first=null then first:=p;  bot:=p
              if top<>null and first=null then first:=top

            Two consequences a plainer reading misses, and both are what a head
            depends on: bot is NOT cleared for a page with no marks, so a head
            set once at \maketitle stays on every later page; and first falls
            back to top, so a page broken mid-section reports the mark in force
            at its own top.

            They are published in assemblePage, which every page passes through,
            BEFORE anything draws a head — a head expands \topmark/\botmark
            while the page is assembled (amsart.cls:325-326), so values set
            after it would be one page late. tex.web updates them at the top of
            fire_up for the same reason.

\splitfirstmark / \splitbotmark belong to \vsplit and are not here.

Tests: the node reaches the vertical list (it did not, and that is how the stub
was found — the arithmetic was already right while the node never arrived); and
the three-page arithmetic above, including the markless page that keeps the
previous bot.

⛔ THE CORPUS SWEEP IS DEFERRED, NOT RUN: 1-minute load average 20.05 against a
ceiling of ~8. This change adds ink to pages without changing their count, so
the channel that can see it is `hashdiff`, not Σ — and a render that times out
under load would report a page count that is simply wrong. It runs behind
`loadwait` and the numbers go on the pull request.

Co-Authored-By: Claude Opus 5 <[email protected]>

* a mark is type 4, so a break may be taken after it (tex.web:3109)

2405.05720 went 9 pages -> 10 with the ink IDENTICAL on both sides (23282), against a reference of 9: the one paper the engine had exactly right, lost. Same content, one more page, because the glue after a mark had stopped being a legal breakpoint -- precedesBreak answered false for markNode, while precedes_break(#) == (type(#) < math_node) is true for mark 4, which the comment above that very function already listed.

Sigma 272 -> 273 and exact 47 -> 46 for that one paper. 'A mark carries no dimension, so no page can change height' was written on #729 before the sweep ran: true, and beside the point. Having no dimension is a different claim from having no effect on where a page MAY break.

Co-Authored-By: Claude Opus 5 <[email protected]>

* a \mark in the PREAMBLE is read and dropped (2405.05720: 10 pages -> 9)

The paper the marks cost its exact match, found by the corpus and fixed by experiment rather than by the mechanism I first proposed. ws-fnl.cls:804 carries a bare \mark{{}{}} at class level, OUTSIDE the document body, and 2405.05720 uses that class. Contributed there, it is material on a page that does not exist yet: 9 pages became 10 with the ink IDENTICAL on both sides (23282 glyph units) against a reference of 9. Dropping the preamble's mark returns it to 9, measured on that paper.

The argument is still SCANNED, so its tokens are consumed exactly as they would be inside the body; only the node is withheld. Nothing in the preamble is typeset (see inBody).

⛔ And the previous commit, which made precedesBreak answer true for a markNode, FIXED NOTHING: the re-sweep came back 273 and 46, byte-for-byte what it was. It is kept because tex.web:3109 says a mark precedes a break (type 4 < 9) and the engine should agree -- not because it repaired that paper. Its comment now says so where the line is, instead of claiming the measurement that refuted it.

Co-Authored-By: Claude Opus 5 <[email protected]>

---------

Co-authored-by: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Nov 18, 2026
…em (#837)

\@gxhead's body read

	\noindent{#1 #2}\hskip-\@tempskipa
	\noindent{#1 #2\par}\nobreak\vskip\@tempskipa

and the space between #1 and #2 is a real space TOKEN: #1 is a parameter,
not a control word, so nothing absorbs it. Expanded in horizontal mode at
the very start of the heading it became interword glue, and every
sectioning heading in every document began that far right of the margin.

LaTeX has no such space — ltsect.dtx:418 is
\@hangfrom{\hskip #3\relax\@svsec}.

Measured against tectonic, leftmost glyph in points from the page edge:

	heading           font    reference   before   after
	\section          14.35   133.77      140.95   133.77
	\subsection       11.96   133.77      139.75   133.77
	\subsubsection     9.96   133.77      138.86   133.77
	body lines         9.96   133.77      133.77   133.77

The right edges land with them — 185.66/185.67, 190.40/190.41,
206.51/206.51 — so the whole line is in place and not merely its start.
The offset scaled with the heading's font, which is what a stray
interword space does and what a fixed indent would not.

⛔ TestGxheadEndsTheHeadingParagraphInsideTheGroup went red on this, and
it was the TEST that was wrong: it matched the literal
`\noindent{#1 #2\par}`, so it pinned the stray space as if it were part
of the invariant. That invariant is the PLACE OF THE BRACE — the \par
inside the style group — and its patterns now name only that. This is the
second drift of that literal; the first was when \nobreak was inserted
between the group and the \vskip, which its own comment records.

The new test guards both branches of \@gxhead and carries a control: a
"fix" that deleted the braces rather than the space would pass the two
refusing rows and set every heading in body type.

⚠ Still missing and deliberately not fixed here: \@startsection's INDENT
argument. LaTeX passes it (\hskip #3 above); \@gxhead is handed only
{style}{title}{afterskip} and never sees it. It is \z@ in every standard
class, so nothing in the corpus moves, but a class that indents its
headings is unobeyed.

Refs #833, Refs #716.

Co-authored-by: Claude Opus 5 <[email protected]>
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