Skip to content

marks travel with page breaking: \mark, \topmark, \firstmark, \botmark - #729

Merged
tannevaled merged 4 commits into
mainfrom
marks-travel
Nov 7, 2026
Merged

tannevaled merged 4 commits into
mainfrom
marks-travel

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

#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"

⚠ Opened on main although it sits on top of #728, so the diff below carries #728's commit too — it drops out on its own when #728 merges. A stacked pull request is closed irrecoverably by GitHub when its base branch is deleted at merge, which has already cost one branch here, so the dependency goes in the text instead of in the base.

⛔⛔ 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 it was 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. Each left the head empty. 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 shows up only as ink that is not on the page. The measurement harness has a whole section about this trap ("the blind spot no channel has"), and it still cost 27 of the 128 corpus papers with a reference their running head through three rounds of fixing the wrong layer.

How it was finally found: a unit test asserting the node reaches the vertical list. The arithmetic was already right while the node never arrived.

What is implemented, from tex.web

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

\topmark / \firstmark / \botmark — republished before each page's head is built, from §1012 (: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 of "the first and last mark on the page" misses, and both are what a running head depends on:

bot is not cleared for a page with no marks a head set once at \maketitle stays on every page after it — which is what amsart relies on
first falls back to top, never to empty a page broken mid-section reports the mark in force at its own top

They are published in assemblePage, the funnel 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 afterwards 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.

Checks, and the one that is deferred

  • go test ./... green, go vet clean.
  • The witness rendered and read at the pixel, above.
  • Two tests: the node reaches the vertical list, and the three-page arithmetic 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. Two reasons it would be worse than no number — this change adds ink to pages without changing their count, so the channel that can see it is hashdiff and not Σ; and a render that times out under load reports a page count that is simply wrong. It is armed behind loadwait and the numbers come here before merge.

🤖 Generated with Claude Code

tannevaled and others added 2 commits November 7, 2026 22:44
#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]>
#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]>
@tannevaled

Copy link
Copy Markdown
Contributor Author

⛔ Not measured, and the gate said so rather than guessing

The corpus sweep this PR promised ran for 49 minutes without ever being allowed to start. The load gate refused the whole time, and then refused to pretend:

charge 1 min = 19.82 > 8, attente (44m0s écoulées)
charge 1 min = 12.16 > 8, attente (45m0s écoulées)
charge 1 min = 16.81 > 8, attente (47m0s écoulées)
charge 1 min = 14.58 > 8, attente (48m0s écoulées)
⛔ charge encore à 10.20 après 49m0s (plafond 8) — RIEN N'A ÉTÉ MESURÉ,
   et un délai dépassé n'est pas un résultat

Exit 1, nothing written, no partial table. That is the behaviour to want: a sweep that had started anyway would have produced page counts, and page counts from renders that time out under load are not wrong in a visible way — they are plausibly wrong, which is worse than absent.

So this PR is not ready to merge, and the reason is the machine rather than the change. Re-armed behind the same gate with a five-hour deadline; the numbers come here when the host is quiet, and nothing should be merged on the assumption they exist.

What is measured and stands on its own meanwhile:

And the one number this change cannot move, which is why hashdiff and not Σ is the channel to look at when the sweep runs: a mark carries no dimension, so no page can change height because of it. If Σ or the page counts move at all, something other than the marks did it, and that is the first thing to read in the table.

tannevaled and others added 2 commits November 7, 2026 23:54
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]>
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]>
@tannevaled

Copy link
Copy Markdown
Contributor Author

Measured, and it cost two wrong mechanisms to get here

étiquette        n   Σ|·|   biais  exacts     provenance
marks729-ctl   154    272     -12      47     main (#728)
marks729-trt   154    273     -11      46     marks, first version
mkpre-trt      154    272     -12      47     this branch now

Σ, bias and exact are back to main's — nothing traded away. And the half Σ cannot see:

154 document(s) comparable(s); 6 ont un rendu DIFFÉRENT, dont 6 à nombre de pages identique
⛔ ces 6-là sont INVISIBLES pour labeldiff et pour score, qui ne comparent que les pages

2111.13456   35 pages (inchangé)   encre 66887 → 68723
2401.03325    9 pages (inchangé)   encre 12213 → 12437
2401.13343   32 pages (inchangé)   encre 69344 → 70243
2402.05579   15 pages (inchangé)   encre 40430 → 41074
2406.10437   36 pages (inchangé)   encre 71922 → 73952
2408.06962   13 pages (inchangé)   encre 32975 → 33539

Six papers gain ink at unchanged page counts: the running head, drawn where it was absent. hashdiff is the only channel that reports them, and it says so about itself.

Six, not #426's twenty-seven. These are the papers whose class brings its own \markboth and reads \topmark/\botmark — amsart and its kin. The rest need our own \markboth to emit a \mark so the pair travels, which is the held kernel-marks branch on #727, with its six test conversions still to do. That is why the count is six here and why the two issues stay separate.

⛔ Two mechanisms I wrote before measuring, both wrong

1. "A mark carries no dimension, so no page can change height." On this PR, before the sweep. The sweep moved Σ 272 → 273, bias −12 → −11, exact 47 → 46: 2405.05720 went from 9 pages to 10 with its ink identical on both sides (23282 glyph units) against a reference of 9 — the one paper the engine had exactly right, lost. Having no dimension is a different claim from having no effect on where a page may break, and I had taken the first for the second.

2. "The glue after a mark stopped being a legal breakpoint." precedes_break(#) == (type(#) < math_node) is true for mark 4, precedesBreak answered false for markNode, and the comment above that very function already listed "mark 4" — so the reading was right and the conclusion was not. The re-sweep came back 273 and 46, byte-for-byte unchanged. The commit is kept, because the engine should agree with tex.web:3109, and its comment now says at the line that it is faithful and repaired nothing, instead of claiming the measurement that refuted it.

The actual cause, found by reading the paper instead of reasoning about it: ws-fnl.cls:804 carries a bare \mark{{}{}} in the preamble, outside the document body, and 2405.05720 uses that class. The stub swallowed it; a primitive contributes it — material on a page that does not exist yet. One build, one render:

with the preamble's mark    10 pages
without                      9 pages   ← the reference

The argument is still scanned, so its tokens are consumed exactly as in the body; only the node is withheld. The regression test is keyed on the mechanism — a \mark before \begin{document} contributes nothing — not on the paper.

What this stands on

  • go test ./... green, go vet clean.
  • The witness read at the pixel: 2111.13456 page 2, y=98.99 "2" → y=99.17 "A POSTERIORI ESTIMATION FOR MULTIPLE-NETWORK POROELASTICITY" "2".
  • The corpus above, control = main at the running mark pair lives under the name the classes write, \@themark #728's merge, swept on a machine the load gate let through — the first two attempts it refused outright rather than produce plausible numbers.

One paper out of 154 caught both of my wrong mechanisms. Neither would have been caught by the suite, and neither would have been caught by Σ alone had the paper not been one of the 47 the engine had exactly right.

@tannevaled
tannevaled merged commit 4d93313 into main Nov 7, 2026
18 checks passed
@tannevaled
tannevaled deleted the marks-travel branch November 7, 2026 23:30
tannevaled added a commit that referenced this pull request Nov 7, 2026
The behaviour is RIGHT and measured; six tests encode the old one, and converting
them is not a thing to rush. Pushed so the work is not lost, not proposed.

WHAT IT DOES, and it is #727's residual:

  \markboth / \markright emit the pair as a \mark beside writing \@theMark, as
  the kernel does (ltpage.dtx:239-244, 265-267) — the pair is for a class to read
  back, the mark is for the page builder;
  \leftmark / \rightmark read \botmark / \firstmark (ltpage.dtx:341-342) instead
  of the single live pair.

MEASURED on three sections forced onto three pages, \pagestyle{headings}:

  page 2 head   "2 DEUXIEME SECTION"
  page 3 head   "3 TROISIEME SECTION"

Each page carries ITS OWN section. With one live pair every page showed the
document's last one, which is exactly what #727 reports. Our \ps@headings
redefines \sectionmark as a \markright, so with one pair the final section won
everywhere.

⛔ WHY IT IS HELD. Six tests fail, all of them probing \leftmark / \rightmark at
DOCUMENT time:

  TestClassKernelDeclarations/marks        TestOnlyNumberedSectionsMark
  TestPagestyleHeadingsDeclaresAHead       TestRunningMarks
  TestAClassThatBringsItsOwnMarkbothReachesTheHead
  TestMarkrightKeepsTheLeftHalf

They are not wrong about the engine; they are wrong about TeX. The values belong
to a page, so outside a page there are none — a real LaTeX answers empty there
too, and latex.ltx has carried a note about this since 1993: "Stopgap solution to
make \leftmark and \rightmark work without initializing mark until the problem is
solved" (ltpage.dtx:318-323), with an upstream \task still open on it. And in THIS
engine the page builder runs after the whole document is read, so document time
can never see a page's marks at all.

So the six have to be rewritten against the DRAWN HEAD rather than against an
expansion — the same move as #728's test, which stopped probing \gotex@rightmark
(the storage) and started probing \rightmark (what a page style reads). Doing that
properly needs a helper for reading a rendered page's text, and six careful
conversions. Rushing them is how a suite ends up asserting the implementation
instead of the behaviour.

Nothing is measured on the corpus either: the machine's 1-minute load was 20.05
against a ceiling of ~8.

Depends on #729 (the mark primitives); this branch sits on top of it.

Co-Authored-By: Claude Opus 5 <[email protected]>
tannevaled added a commit to go-tex/docs that referenced this pull request Nov 8, 2026
… fixes (#25)

The marks work is the clearest case the page-count barometer cannot report,
so it belongs beside the hashdiff table that already explains why: 6 of 154
renders differ at IDENTICAL page counts, and 27 of the 128 corpus papers
with a reference PDF now get the head they had been missing, for zero
movement in the three numbers -- a head replaces blank space in a header
that was already reserved.

The mechanism is written down with the sources it was ported from rather
than asserted, because every part of it is a decision someone can check:
fire_up derives the three quantities a head is written from
(tex.web:19718-19729, :19782-19789) -- topmark is the previous page's
botmark, firstmark is this page's first mark or else topmark, and botmark is
this page's last mark and is NOT cleared on a page carrying none, which is
what makes a head persist across a chapter. Above that, latex.ltx keeps the
left/right pair in one token list, \@theMark (ltpage.dtx:355), read back
through \@firstoftwo/\@secondoftwo (:167-174, :341-342), and \@markright
keeps the left half on purpose -- which is why \markright in a \section does
not erase the chapter.

And the lesson, in a callout because it generalises past this engine: the
change took four fixes, three of them correct and insufficient, because a
one-line substrate stub -- \def\mark#1{} -- accepted its argument and
discarded it one layer BELOW all three. Each correct fix above it changed
nothing observable and so looked wrong. What found it was a different
question rather than a better fix: a test asking whether the node ARRIVES,
not whether the layer emitting it is right. Any stub that accepts input and
drops it will outlive every repair made above it.

Built locally with the pinned theme submodule and checked in the OUTPUT,
not just for a zero exit: the prose, the table row and the callout's inner
text are all present in public/packages/engine/index.html, and no literal
shortcode survived into the HTML.

Refs go-tex/engine#426, go-tex/engine#729

Co-authored-by: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Nov 16, 2026
* HELD: the kernel's own \leftmark/\rightmark read the page's marks (#727)

The behaviour is RIGHT and measured; six tests encode the old one, and converting
them is not a thing to rush. Pushed so the work is not lost, not proposed.

WHAT IT DOES, and it is #727's residual:

  \markboth / \markright emit the pair as a \mark beside writing \@theMark, as
  the kernel does (ltpage.dtx:239-244, 265-267) — the pair is for a class to read
  back, the mark is for the page builder;
  \leftmark / \rightmark read \botmark / \firstmark (ltpage.dtx:341-342) instead
  of the single live pair.

MEASURED on three sections forced onto three pages, \pagestyle{headings}:

  page 2 head   "2 DEUXIEME SECTION"
  page 3 head   "3 TROISIEME SECTION"

Each page carries ITS OWN section. With one live pair every page showed the
document's last one, which is exactly what #727 reports. Our \ps@headings
redefines \sectionmark as a \markright, so with one pair the final section won
everywhere.

⛔ WHY IT IS HELD. Six tests fail, all of them probing \leftmark / \rightmark at
DOCUMENT time:

  TestClassKernelDeclarations/marks        TestOnlyNumberedSectionsMark
  TestPagestyleHeadingsDeclaresAHead       TestRunningMarks
  TestAClassThatBringsItsOwnMarkbothReachesTheHead
  TestMarkrightKeepsTheLeftHalf

They are not wrong about the engine; they are wrong about TeX. The values belong
to a page, so outside a page there are none — a real LaTeX answers empty there
too, and latex.ltx has carried a note about this since 1993: "Stopgap solution to
make \leftmark and \rightmark work without initializing mark until the problem is
solved" (ltpage.dtx:318-323), with an upstream \task still open on it. And in THIS
engine the page builder runs after the whole document is read, so document time
can never see a page's marks at all.

So the six have to be rewritten against the DRAWN HEAD rather than against an
expansion — the same move as #728's test, which stopped probing \gotex@rightmark
(the storage) and started probing \rightmark (what a page style reads). Doing that
properly needs a helper for reading a rendered page's text, and six careful
conversions. Rushing them is how a suite ends up asserting the implementation
instead of the behaviour.

Nothing is measured on the corpus either: the machine's 1-minute load was 20.05
against a ceiling of ~8.

Depends on #729 (the mark primitives); this branch sits on top of it.

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

* the six mark tests read the drawn HEAD, so kernel-marks is no longer held

They probed \leftmark/\rightmark at DOCUMENT time, where those now expand \botmark/\firstmark -- values that belong to a page, published by the page builder, which runs after the whole document has been read. A real LaTeX answers empty there too; latex.ltx has carried a note about it since 1993 (ltpage.dtx:318-323, upstream \task still open). So the tests were not wrong about the engine, they were wrong about TeX.

The split they become: SEMANTICS at document time through \@theMark, the kernel's own name for the live pair (ltpage.dtx:355) -- a documented variable classes write and read, amsart among them -- and REACHABILITY through the head actually drawn, read with pageText(). TestClassKernelDeclarations/marks, TestMarkrightKeepsTheLeftHalf and TestRunningMarks take the first; TestPagestyleHeadingsDeclaresAHead, TestOnlyNumberedSectionsMark and TestAClassThatBringsItsOwnMarkbothReachesTheHead take the second.

⛔ Two things the conversion exposed. The class-own-markboth fixture copied only the \@theMark half of amsart's idiom and left out \mark{\the\@temptokena}: enough while \rightmark read the pair directly, and not a class at all once the pair travels -- a fixture missing the line that makes the mechanism work was testing it not working. And the needles carry no spaces, because pageText collects glyphs and not the glue between them.

The obsolete comment in classkernel_test.go went with it: it stated the divergence as permanent ("which this page builder does not do yet").

---------

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