Repository navigation
Description
A running head shows the document's last mark on every page, not the mark in force on that page. It became visible with #726, which draws the head at all; before that the band was reserved and left empty, so the content was never seen to be wrong.
Witness
fontcmp -pagefill's headings document has 26 sections. Page 1's head reads 26 SECTION NUMERO 26, against the oracle's 1 SECTION NUMERO 1 1.
Not off by one — the last section in the document, on the first page.
Why
There is one live pair and it is global (classkernel.go:633-637):
\gdef\gotex@leftmark{}
\gdef\gotex@rightmark{}
\def\markboth#1#2{\protected@xdef\gotex@leftmark{#1}\protected@xdef\gotex@rightmark{#2}}and this engine assembles pages after the whole document has run, so the live pair at assembly time is the final mark the document set. classkernel.go:626-632 already says so, and says what is missing: "real LaTeX carries the pair through TeX's \mark / \firstmark / \botmark … The difference needs marks to travel with page breaking, which this page builder does not do yet."
What TeX does, which is the shape of a fix
tex.web:7864-7866 defines the three:
top_mark_code=0 {the mark in effect at the previous page break}
first_mark_code=1 {the first mark between top_mark and bot_mark}
bot_mark_code=2 {the mark in effect at the current page break}
and tex.web:19718-19729 maintains them at every break:
if bot_mark<>null then
begin … top_mark:=bot_mark; … first_mark:=null; end;
<Put the optimal current page into box 255, update first_mark and bot_mark, …>
if (top_mark<>null)and(first_mark=null) then
begin first_mark:=top_mark; … end;
So: the previous page's end becomes top_mark; first_mark is cleared and then filled by scanning this page's mark nodes; and a page carrying no mark inherits top_mark — which is what keeps a head correct across a page with no new section.
LaTeX reads them through those names (latex.ltx:13360-13361):
\def\leftmark{\expandafter\@leftmark\botmark\@empty\@empty}
\def\rightmark{\expandafter\@rightmark\firstmark\@empty\@empty}\ps@headings puts \rightmark in \@oddhead (latex.go:898), so a running head asks for \firstmark — the first mark on the page being shipped. We answer with the document's last.
It needs a mark node riding the vertical list, the way pageStyleNode already rides it for \thispagestyle (pagenum.go:28-35), and first/bot computed per page where the break is chosen.
How much it matters
population over .tex,.cls,.sty for pagestyle\{(headings|myheadings)\}: 27 of the 154 measured papers. Those are the ones whose head tracks sections; a head set once — a title, a preprint banner — is unaffected, since the single live pair is then the right one.
⚠ Worth being honest about the direction: before #726 those 27 drew no head, so the words were absent; now they are present and, for the section-tracking ones, wrong. That is not obviously worse for a word-recall metric, and it is clearly better geometrically (#726 recovers 31.7pt of text per page). But it is a visible defect where there was a visible absence, and that is the argument for doing this one next.
Activity
the running mark pair lives under the name the classes write, \@theMark
the running mark pair lives under the name the classes write, \@theMark
tannevaled commentedon Nov 7, 2026
This is not a refinement of the head — for amsart it is the ONLY route to one
I filed this as "the head draws, with the wrong content: the document's last mark on every page". That is true for our own
\ps@headings. For the class that 27 of the 128 papers in #426 use, it understates the issue: there is no head at all without marks, because amsart reads its heads straight out of TeX's marks (texmf/amsart.cls:325-326):It also brings its own
\markboth, which emits\mark{{#1}{#2}}(:335-340). So amsart never reads\@themarkback — it only writes it — and #728 (\@themarkunder the kernel's name) does nothing for it. Measured, not inferred:2111.13456rendered with #726 and #728 still shows only the folio in the band,y=98.99 size=7 "2".And the engine has no mark primitives whatsoever:
returns five hits, all inside comments.
\markis undefined, which is why amsart's\markbothcontributes nothing and why those papers need-lenient.What it takes, from the reference
\mark{…}as a node on the vertical list, its token list expanded at mark time, travelling with page breaking.pageStyleNode(pagenum.go:28-35) is the precedent:\thispagestylesolves the same "which page does this land on" problem by contributing a node and letting the builder find it, "which is how TeX gets the same answer".\topmark,\firstmark,\botmarkmaintained per page —tex.web:7864-7866, with the per-break arithmetic at:19718-19729:\topmark\botmark\firstmark\topmarkif it has none\botmark\topmarkif it has noneThey must hold the page's values before the head is drawn, since the head expands them during assembly — which is where our single live pair gets away with being wrong today.
\splitfirstmark/\splitbotmarkbelong to\vsplitand are out of scope here.Closing #426 means doing this, so the two are one piece of work. I am keeping them as separate issues because the populations differ — #426 counts the papers losing a head, this one names the mechanism — but neither closes without it.
the running mark pair lives under the name the classes write, \@theMark…
tannevaled commentedon Nov 7, 2026
Measured: each page now carries its own section. Branch
kernel-marks, HELDWith #729's mark primitives under it, the kernel's own accessors can read the page's marks instead of the single live pair. Three sections forced onto three pages,
\pagestyle{headings}:That is this issue. With one live pair every page showed the document's last section, because our
\ps@headingsredefines\sectionmarkas a\markrightand the final one wins everywhere.What the branch does, straight from the kernel:
ltpage.dtx:239-244and:265-267for 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-342for the accessors.⛔ Why it is held rather than proposed
Six tests fail, all of them probing
\leftmark/\rightmarkat document time:They are not wrong about the engine. They are wrong about TeX: those values belong to a page, so outside a page there are none, and a real LaTeX answers empty there too.
latex.ltxhas carried a note about this awkwardness since 1993 — "Stopgap solution to make\leftmarkand\rightmarkwork without initializing mark until the problem is solved" (ltpage.dtx:318-323) — with an upstream\taskstill open on it. 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. That is the same move #728's test made — it stopped probing
\gotex@rightmark, the storage, and started probing\rightmark, what a page style reads — and doing it properly needs a helper for reading a rendered page's text plus six careful conversions. Rushing that is how a suite ends up asserting the implementation instead of the behaviour, which is the defect this whole chain has been about.Nothing is measured on the corpus either: the machine's 1-minute load average was 20.05 against a ceiling of ~8.
The branch is pushed so the work is not lost, and reported here rather than left as a branch with no pull request — which is precisely the invisible work
branchscanexists to find. It opens as a pull request after #729 merges and the six tests are converted.marks travel with page breaking: \mark, \topmark, \firstmark, \botmark (
HELD: the kernel's own \leftmark/\rightmark read the page's marks (#727)
the kernel's own marks read the page's, closing #727 (#732)