Skip to content

maths: flattening resolves notation, so an assignment-bodied macro stays a token (1 page → 8) - #545

Merged
tannevaled merged 2 commits into
mainfrom
math-flatten-skips-assignments
Oct 4, 2026
Merged

tannevaled merged 2 commits into
mainfrom
math-flatten-skips-assignments

Conversation

@tannevaled

@tannevaled tannevaled commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

flattenMathBody expands a formula's own source so go-tex/math sees notation rather than macro names. A macro whose replacement text is an assignment has to be left for the stomach: expanding it hands back the assignment's tokens, and the engine then expands the very name the assignment was about to redefine.

The self-redefining idiom makes that non-terminating. quantumarticle.cls:1108-1109 is the textbook form — nothing the first time, a separator after that:

\def\@@@comma{\def\@@@comma{,}}
\def\@@commaspacebefore#1{\@@@comma{}#1}

Reached through \ensuremath in an author block, 2607.22466 spun \@@@comma 400 times and pushed {,} to 200 001 frames deep.

Measured

v0.229.0 with this
pages 1 8
groups still open 4 0
runaway yes gone

The context was named, not guessed

GOTEX_TRACE=1 gave the 127-entry chain ending \etb@forlistloop → \@@commaspacebefore → \@@@comma x268, and a Go stack gave the rest:

doMath → makeMath → renderMathResolvingMacros → expandMacroInMathSource
       → flattenMathBody → expandList → getXToken

That is why the guard sits in the expansion path and not in flattenMathBody's noexp pre-pass: the macro is not in the source being flattened, it arrives mid-expansion through etoolbox's \forlistloop, so marking names up front cannot reach it. That version was written first and measured — it changed nothing at all, which is a refuted hypothesis rather than a near miss.

Note the engine embeds the real etoolbox.sty, so none of this is an emulation artefact.

Regression control — both channels, complete

The math path touches every paper with a formula, so a page count alone is not enough: a change that traverses maths needs the equation census beside it, or a dropped formula hides inside an unchanged page total. Both run against a binary built from main, over the 154-paper fidelity list, which contains none of the subject paper.

channel result
pages, paper by paper 154 read: 0 up, 0 down, 154 identical, 0 unreadable
equations (measure mathdrop) Σ 138 → 138, Δ +0 — no trigger gone, appeared, risen or fallen

⛔ Why the guard is on SELF-reference and not on "the body assigns"

The first version refused to expand every assignment-bodied macro. The page channel approved it — 4 papers up, none down — and the equation census showed the opposite:

Σ dropped equations  138 -> 158  (+20)
  \def      disappeared as a trigger   (-2)
  \unskip   disappeared                (-1)
  \@forloop APPEARED                  (+23)

A loop macro assigns to other names and must keep expanding. Only a macro that redefines itself cannot be flattened. That is the whole difference between the two versions, and the page count could not see it.

Tests

Only the first is a witness for this change: without the fix it reports the runaway. The second asserts the macro still takes effect — a guard that dropped the token instead of deferring it would pass the first test while silently losing every separator the idiom exists to produce. It passes with or without the fix, by design.

Full suite green, go vet clean.

Related: #517, #543, #544.

🤖 Generated with Claude Code

tannevaled and others added 2 commits October 4, 2026 18:25
…GNMENT stays a token

flattenMathBody expands the formula's own source so go-tex/math sees notation rather
than macro names. A macro whose replacement text IS an assignment must be left for the
stomach: expanding it hands back the assignment's tokens, and the engine then expands
the very name the assignment was about to redefine.

The self-redefining idiom makes that non-terminating. quantumarticle.cls:1108-1109 is
the textbook form — nothing the first time, a separator after that:

	\def\@@@comma{\def\@@@comma{,}}
	\def\@@commaspacebefore#1{\@@@comma{}#1}

Reached through \ensuremath in an author block, 2607.22466 spun \@@@comma 400 times and
pushed {,} to 200 001 frames deep. Measured:

	pages 1 -> 8, groups still open 4 -> 0, runaway gone

The Go stack named the context rather than a guess: doMath -> makeMath ->
renderMathResolvingMacros -> expandMacroInMathSource -> flattenMathBody -> expandList.

The guard is in the expansion path, NOT in flattenMathBody's noexp pre-pass, because
the macro is not in the source being flattened — it arrives mid-expansion through
etoolbox's \forlistloop, so marking names up front cannot reach it. That version was
written first and measured: it changed nothing at all.

Two tests, and only the first is a witness for this change: without the fix it reports
the runaway. The second asserts the macro still TAKES EFFECT, because a guard that
dropped the token instead of deferring it would pass the first while silently losing
every separator the idiom exists to produce.

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

The first version refused to expand every macro whose body began with an assignment.
The page channel liked it — 4 papers up, none down over the 154-paper list — and the
equation census showed what pages cannot see:

	Σ dropped equations 138 -> 158 (+20)
	\def     disappeared as a trigger   (-2)
	\unskip  disappeared                (-1)
	\@forloop APPEARED                 (+23)

A loop macro assigns to OTHER names and must keep expanding; only a macro that
redefines ITSELF cannot be flattened. With the guard narrowed to that:

	Σ dropped equations 138 -> 138 (+0), no trigger gone, appeared, risen or fallen
	2607.22466 still 1 page -> 8, groups 4 -> 0, runaway gone

Co-Authored-By: Claude Opus 5 <[email protected]>
@tannevaled
tannevaled merged commit cde92b1 into main Oct 4, 2026
18 checks passed
@tannevaled
tannevaled deleted the math-flatten-skips-assignments branch October 4, 2026 16:51
tannevaled added a commit that referenced this pull request Oct 4, 2026
The figure this README carries went stale within the hour, which is why it names the
population it was measured on rather than standing alone. Re-measured on main with
#543, #544 and #545:

	papers rendering ONE page, of the 71 the sweep flags
	  when the series began   12
	  earlier today            6
	  now                      1   (2607.05497, diagnosed in #517)

#544 took three of them from 1 page to 21, 15 and 15 by making \vspace a macro again,
and #545 took a fourth from 1 to 8 by leaving a self-redefining macro for the stomach.

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