Skip to content

the kernel's own marks read the page's, closing #727 - #732

Merged
tannevaled merged 3 commits into
mainfrom
kernel-marks
Nov 16, 2026
Merged

tannevaled merged 3 commits into
mainfrom
kernel-marks

Conversation

@tannevaled

@tannevaled tannevaled commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Closes #727. Refs #426 — this reaches the rest of its papers, but that issue stays open until the 18 changed renders are each read rather than inferred (see the comments below).

Our own \markboth/\markright emit the pair as a \mark, and \leftmark/\rightmark read the marks of the page being shipped instead of the single live pair.

\def\markboth#1#2{\protected@xdef\@themark{{#1}{#2}}\mark{\@themark}}
\def\markright#1{\expandafter\@markright\@themark{#1}\mark{\@themark}}
\def\leftmark{\expandafter\@leftmark\botmark\@empty\@empty}
\def\rightmark{\expandafter\@rightmark\firstmark\@empty\@empty}

ltpage.dtx:239-244 and :265-267 for emitting the mark beside writing the pair — the pair is for a class to read back, the mark is for the page builder — and :341-342 for the accessors. It sits on #729, which made \mark travel.

Measured: main puts a section from the FUTURE in the head

Three sections forced onto three pages, \pagestyle{headings}, same file, two binaries. Page 2's head:

head of page 2
main 3 TROISIEME SECTION
this branch 2 DEUXIEME SECTION

main shows the document's last section on every page — so a reader on page 2 is told they are in section 3, which has not started yet, beside the folio 2. Our \ps@headings redefines \sectionmark as a \markright, and with one live pair the final section wins everywhere.

The six tests this was held for

They probed \leftmark/\rightmark at document time, which now expands \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, and latex.ltx has carried a note about that since 1993 (ltpage.dtx:318-323, with an upstream \task still open). The tests were not wrong about the engine; they were wrong about TeX.

They become a deliberate split:

asked at document time, through \@themark asked of the drawn head, through pageText()
TestClassKernelDeclarations/marks TestPagestyleHeadingsDeclaresAHead
TestMarkrightKeepsTheLeftHalf TestOnlyNumberedSectionsMark
TestRunningMarks TestAClassThatBringsItsOwnMarkbothReachesTheHead

\@themark is the kernel's own name for the live pair (ltpage.dtx:355) — a documented variable classes write and read, amsart among them — so the left column asserts an interface and not an internal. What it cannot show is reachability, which is exactly what the right column is for. That distinction is the whole lesson of #728: a test that names the storage cannot tell a mark that was set from a mark that is reached.

⛔ Two things the conversion exposed

My own fixture was not a class. TestAClassThatBringsItsOwnMarkbothReachesTheHead copied the \@themark half of amsart's idiom and left out \mark{\the\@temptokena}. That was enough while \rightmark read the pair directly, and it is not a class at all once the pair travels — a fixture missing the line that makes the mechanism work was testing the mechanism not working. It now emits the mark, as amsart does.

An obsolete comment went with it. classkernel_test.go stated the divergence as permanent: "the difference needs marks to travel with page breaking, which this page builder does not do yet". It does now.

Checks

  • go test ./... green across the repository, go vet clean, gofmt -l . silent.
  • The page-2 A/B above, read at the pixel from both binaries.
  • Corpus sweep against main running; its numbers come here before merge. hashdiff is the channel to read it on — a head's text changing moves ink, not page counts.

🤖 Generated with Claude Code

tannevaled and others added 2 commits November 8, 2026 00:31
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]>
…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").
@tannevaled

Copy link
Copy Markdown
Contributor Author

Corpus, control = main (binaries built explicitly, no history rewritten)

étiquette     n   Σ|·|   biais  exacts
kmctl       154    272     -12      47     main
kmtrt       154    272     -10      46     this branch

Σ flat, bias −12 → −10 (two pages closer to zero), and one exact lost. Then the channel Σ cannot see:

154 comparable; 18 render DIFFERENTLY, 16 of them at identical page counts
⛔ ces 16-là sont INVISIBLES pour labeldiff et pour score

18 papers change, 16 of them invisible to the page metric. That is the head now carrying its own page's mark, on documents that use our \markboth — the population #426 counts and which #729 could not reach.

The two that moved pages, named

paper before after ref deviation
2402.04711 194 195 198 −4 → −3, closer
2405.05734 16 17 16 +0 → +1, exact lost

⛔ 2405.05734's ink is identical on both sides — 49141 → 49141 — with one more page. Same content, one more page, which is the signature of a changed breakpoint and not of changed material. And that is expected here rather than a surprise: \markboth/\markright now emit \mark nodes, and a mark permits a break after it (precedes_break(#) == (type(#) < math_node), mark is type 4 < 9 — the rule #729 made this engine obey). Emitting marks therefore adds legal breakpoints, and the page builder is free to use one.

So the engine is more faithful and one paper's exact match was collateral. Σ says the trade is even (those two alone: 4 → 4) and the bias says it is slightly favourable.

One figure worth naming because its direction is the opposite of the headline

2405.10478: 22 pages unchanged, ink 65786 → 65588, a drop of 198. Every other mover gains ink (2407.18384: 516945 → 523615 on a 315-page document). A head gaining text can only add ink, so a drop means the head's text got shorter — consistent with per-page marks replacing "the document's last section", which is what main showed on every page, with the section the page is actually in. That is the intended effect and the drop is evidence of it working.

⚠ I have not rendered that paper to read its head, so the explanation above is inference from the ink and the mechanism, not a measurement. What would settle it is reading page 2's head text on both binaries, as was done for 2111.13456 on #729.

@tannevaled

Copy link
Copy Markdown
Contributor Author

⛔⛔ Correction: that ink drop is a REGRESSION, and this branch must not merge

I wrote, one comment up, that 2405.10478's ink falling 65786 → 65588 was "consistent with per-page marks replacing the document's last section with the section the page is actually in… the intended effect and the drop is evidence of it working", and flagged that I had not rendered it. I have now rendered it, and it is the opposite.

Page 3's running head, same file, two binaries:

main          "References"   folio 3
this branch   "."            folio 3

The head went from References to a single full stop. That is not a shorter mark, it is a broken one — and it is on a paper whose page count did not move, which is exactly why Σ and labeldiff reported nothing and why I reached for an explanation instead of a render.

So the honest reading of the whole set changes with it: of the 18 papers whose render differs, I have verified one by eye and it is wrong. The other 17 are now unknown rather than good, including the ones whose ink rose — a head can gain ink by being wrong as easily as by being right.

#732 is not mergeable and I am not asking for it. Three things it needs:

  1. the cause of References → . — the suspects are the pair's re-expansion in \mark{\@themark} and \@secondoftwo meeting something that is not two groups;
  2. the other 17 read, not inferred, with the same method (hashdiff names them, so the list is in hand);
  3. a witness that would have caught this. My three-section witness on A running head shows the document's last mark on every page: marks do not travel with page breaking #727 passed — each page carried its own section — because it exercises \sectionmark on a document whose marks are simple. 2405.10478 has a References head, so a \markboth from \thebibliography, and that path is not in any witness here.

⛔ And the method lesson, since it is the second time in two days: I had the measurement that contradicted me (an ink figure moving the wrong way, alone among eighteen), named it as worth explaining, and then explained it instead of looking. The flag I attached — "inference from the ink and the mechanism, not a measurement" — was correct and should have been a blocker, not a caveat.

@tannevaled

Copy link
Copy Markdown
Contributor Author

⛔ Correcting the correction: it is not a regression. The branch is right and main was wrong

I called the References → . change a regression one comment up. It is not, and the paper's own source says so — 2405.10478/main.tex:112:

\title[\textcolor{white}{.}]{GridapTopOpt.jl: A scalable Julia toolbox for level set-based topology optimisation}

The author gives \title a short-title argument of a white full stop, deliberately, so that the running head comes out blank. So:

page 3's head
main References the document's last mark, leaking onto a page that is not the bibliography
this branch . in white the short title the class puts there, which the author made invisible

And the white is honoured: page 3 carries two white fills, and the . I read came out of the fill-opacity="0" searchable text layer, not from visible ink. On screen that head is blank, which is what the reference shows and what the document asked for.

So the ink falling 65786 → 65588 is the intended effect after all: a wrong word removed, a deliberately invisible character in its place. My first reading of it was right, my "regression" was wrong, and what settled it was neither inference nor the look of the glyph but the paper's own source line.

What this leaves standing, and what it does not

  • Still true: of the 18 papers whose render differs, I have now verified one. The other 17 are unverified, and a head can gain ink by being wrong as easily as by being right. That is work, not an assumption to make either way.
  • Still true: 2405.05734 goes 16 → 17 pages with identical ink, because emitting \mark nodes adds legal breakpoints (precedes_break, mark is type 4 < 9). One exact match lost, one paper closer, Σ flat, bias −12 → −10.
  • No longer true: that this branch mangles a head.

⛔ The method lesson is the one worth keeping, and it is sharper than "measure, don't infer": I inferred, then I looked at the pixels and still got it wrong, because a single period in a running head looks exactly like a broken mark. What distinguished them was two more facts — the source line and the fill colour. Looking is not one act; "read the pixels" is only sufficient when you also know what the document asked for.

@tannevaled

Copy link
Copy Markdown
Contributor Author

Held, and now with the reason measured rather than asserted. I said I would read the changed renders instead of inferring them; here is what they say.

The sweep

hashdiff kmctl kmtrt over the 154-document corpus: 18 renders differ, 16 of them at identical page counts — so sixteen are invisible to labeldiff and to score, which compare page counts only.

Two moved by a page, and with the reference as labeldiff's third argument they move in opposite directions:

document before after reference deviation
2402.04711 194 195 198 −4 → −3 (toward the reference)
2405.05734 16 17 16 +0 → +1 (it was exact)

⛔ Σ on those two alone: 4 → 4. A net movement of zero that hides a document leaving exactness. The aggregate would have reported this change as costless.

What 2405.05734 is

\documentclass[lettersize,journal]{IEEEtran}
...
\markboth{Journal of \LaTeX\ Class Files,~Vol.~18, No.~9, September~2020}%
{How to Use the IEEEtran \LaTeX{} Templates}
\maketitle

Unmodified IEEEtran template boilerplate, and the \markboth sits in the body, immediately before \maketitle.

With this change that call emits a \mark node, and a mark node is a legal breakpoint — faithfully so: precedes_break(#) == (type(#) < math_node), and mark_node is 4 against math_node's 9, so real TeX also breaks there. An extra legal breakpoint on a page that is already nearly full can move the break, and one page follows.

So the hypothesis is that this page is the correct consequence of a mark finally existing, and that it reveals a separate error it used to mask. That is a hypothesis, not a finding, and it is precisely the shape that has been wrong before here: a change that is right in mechanism and still costs a document its exactness needs the page itself read, not the mechanism re-argued.

Also unresolved: four documents LOSE ink at identical page counts

document ink
2405.10478 65786 → 65588 (−198)
2401.17012 31973 → 31927 (−46)
2401.11909 20616 → 20584 (−32)
2311.08855 39442 → 39427 (−15)
2311.08861 16702 → 16690 (−12)

Only the first is explained: 2405.10478's own main.tex:112 is \title[\textcolor{white}{.}]{…}, so its running head is deliberately a white full stop and losing that ink is correct. The other four are unexplained, and ink disappearing from a head is the direction that could mean a head lost rather than a head gained.

Against that, eleven documents gain ink at unchanged pagination — 2407.18384 by 6670 and 2209.13768 by 570 — which is the expected shape of heads appearing where there were none.

What it would take to merge

  1. Read 2405.05734's pages around the break at both labels and say whether the extra page is the faithful consequence of the mark breakpoint or a misplaced mark.
  2. Read the heads of the four ink-losing documents and confirm each loss is a head that should be absent.

Until both are done this stays shut, because the figure that would normally justify it — Σ — is exactly the figure that cannot see what this change did.

🤖 Generated with Claude Code

@tannevaled

Copy link
Copy Markdown
Contributor Author

The corpus sweep this pull request owed, and it costs Σ 2

"Corpus sweep against main running; its numbers come here before merge."

Here they are. gotex-abdiff, head merged with today's main first, 154 papers:

base origin/main  fe2828b5
head HEAD         6bfd7840     (kernel-marks merged with main)

scored            154 paper(s)
Σ|page deviation| 294 -> 296   (+2)
exact pagination   39 ->  39   (+0)
papers moved        2   (0 toward the reference, 2 away, 0 sideways)
  2402.04711     201 -> 202   (reference 198)
  2405.05734      17 ->  18   (reference  16)

Two papers gain a page, both already over the reference, and none moves toward it. Exact pagination does not move.

What the description predicted, and how this differs

The body says the change should be invisible to Σ:

6 corpus papers gain ink at identical page counts, invisible to Σ and visible only to hashdiff

and names the mechanism by which a mark can change a page count, as a thing already handled:

A \mark in a class preamble is read and dropped: ws-fnl.cls carries one, and contributing it to a page that does not exist yet turned 9 pages into 10 with the ink identical.

Two papers here do exactly that — 201→202 and 17→18, each one page. Either the preamble case is not fully handled, or a second route contributes a mark to a page that is not open yet. I have not established which, and the two named papers are where to look.

⚠ What this measurement is and is not

  • Both arms share it, so the comparison stands: GOTEX_PDFRENDER was unset, which leaves PDF figures as empty boxes on 83 of the 154 papers. The absolute Σ is therefore not this engine's true fidelity; the difference is what this reads.
  • No sampling. A page count is deterministic, so one run per arm is the whole of it — unlike a timing, which this is not.
  • The head was merged with today's main first, because the branch was four days behind and a sweep against a stale base measures the gap as well as the change.

And a correction to what I said about this pull request

I reported it for two days as "green and parked, blocked on a quiet machine". The machine was part of it, but two other things I said were blocking were not: the corpus was on this disk all along, and the curated list and its reference page counts were in a different directory than I had looked in. Once resolved, the sweep took four minutes.

It is still a real result that the change costs 2. The decision — whether a correct running head is worth two pages on two papers, or whether those two papers are a second defect to fix first — is not mine to take alone, and the first measurement of it is above.

🤖 Generated with Claude Code

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.

A running head shows the document's last mark on every page: marks do not travel with page breaking

1 participant