Skip to content

engine: make the font-size commands \tiny…\Huge functional again - #76

Open
tannevaled wants to merge 1 commit into
mainfrom
fix-dead-fontsize-commands
Open

engine: make the font-size commands \tiny…\Huge functional again#76
tannevaled wants to merge 1 commit into
mainfrom
fix-dead-fontsize-commands

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

What was broken

A size clo (size10/size11/size12.clo) redefines \normalsize, \small, …, \Huge as \@setfontsize\<cmd>\<size>{<leading>}, and the engine's \@setfontsize is a no-op gobble. So after the class loaded, every size command was dead — a heading set with \Large, a caption with \small, a footnote with \footnotesize all rendered at the body size with the body leading. Measured before this change, every command sat at the base size with the base \baselineskip at 10pt, 11pt and 12pt.

The fix

Same route as #75 (which revived \normalsize's base size): drive the size through the font system, not by making \@setfontsize a live primitive. At \begin{document}, \gotex@sizeclosetup reads the (size, leading) the active clo baked into each command's body and redefines it as a \protected macro:

\gotexsize<permille>\relax\gotexleading<leading>sp\relax <clo display-skip/list tail>
  • \gotexsize scales the class base font (as \large already did) to the clo's absolute point size.
  • \gotexleading (new primitive) sets the matching \baselineskip, group-scoped via a new save-stack entry.
  • The clo's own tail — \abovedisplayskip/\belowdisplayskip glue and \@listi params that \small/\footnotesize carry — is preserved (the dead gobble left it running).
  • \protected keeps it robust in a moving context (a section title into the ToC, a caption into the LoF) — exactly the failure mode engine: honour a class's 11pt/12pt base size in the font system #75 avoided by refusing to make \@setfontsize functional.
  • Reading off the active clo gives each class its own table: \Large in a 12pt document is the 12pt clo's 17pt on 22pt leading.
  • \normalsize is deliberately not rewired (engine: honour a class's 11pt/12pt base size in the font system #75 owns its base size/leading; it is called on nearly every reset, so hardcoding a leading would fight \linespread/setspace).

Per-command proof (glyph size / \baselineskip), matches the clo byte-for-byte

base tiny scriptsize footnotesize small large Large LARGE huge Huge
10pt 5/6 7/8 8/9.5 9/11 12/14 14/18 17/22 20/25 25/30
11pt 6/7 8/9.5 9/11 10/12 12/14 14/18 17/22 20/25 25/30
12pt 6/7 8/9.5 10/12 11/13.6 14/18 17/22 20/25 25/30 25/30

Layout impact — MIXED, not a clear win (please review before merging)

On the -layout harness (40 papers, seed 1, tectonic ground truth):

config mean divergence total page-count error
before (dead) 7.760 123
this PR (size + leading) 8.377 133
size-only variant 7.998

The aggregate is a net regression, driven almost entirely by one algorithm2e paper (2508.20008, whose \SetCommentSty is only partly supported): excluding that single outlier the mean improves 7.929 → 7.879. Heading-heavy papers gain (one 2608.07597: 13.76 → 6.29); caption/footnote/\small-heavy papers lose a little, because the engine already packs denser than tectonic and correct sizing amplifies that pre-existing line-break/page-build divergence. Counts: 3 improved (2 large), 7 slightly worsened, 18 unchanged.

This is a correctness fix (the commands were genuinely dead); the layout metric should reward it once dense-region breaking matches tectonic more closely. Opening for review, not merging.

Verification

🤖 Generated with Claude Code

A size clo (size10/size11/size12.clo) redefines \normalsize, \small, …, \Huge
as \@setfontsize\<cmd>\<size>{<leading>}, and the engine's \@setfontsize is a
no-op gobble — so after the class loaded, EVERY size command was dead. A heading
set with \Large, a caption with \small, a footnote with \footnotesize all came
out at the body size, with the body leading: wrong glyph size AND wrong vertical
space on essentially every document (proven: at 10/11/12pt every command sat at
the base size with the base \baselineskip).

Revive them the way #75 handled \normalsize — through the FONT SYSTEM, not by
making \@setfontsize a live primitive. At \begin{document} (\AtBeginDocument),
\gotex@sizeclosetup reads the (size, leading) the ACTIVE clo baked into each
command's body and redefines the command as a \protected macro

	\gotexsize<permille>\relax\gotexleading<leading>sp\relax <clo tail>

where \gotexsize scales the class base font (as \large already did) to the clo's
absolute point size, \gotexleading sets the matching \baselineskip (a new
primitive, group-scoped via a new save-stack entry), and the clo's own tail — the
\abovedisplayskip / \belowdisplayskip glue and \@Listi list parameters that
\small/\footnotesize carry — is preserved, since the dead gobble left it running.
Reading the values off the active clo gives each class its own table, so \Large
in a 12pt document is the 12pt clo's 17pt on 22pt leading, not the 10pt one.

Marking the macro \protected is what keeps it robust in a moving context — a
section title flowing into the ToC, a caption into the LoF — exactly the failure
mode #75 avoided by refusing to make \@setfontsize functional. \normalsize is
deliberately left as the dead gobble: #75 owns the base size and leading, and
\normalsize is called on nearly every reset, so hardcoding a \baselineskip into
it would fight a document's own \linespread/setspace and densify everything.

Per-command proof (glyph size / \baselineskip), matching the clo byte-for-byte:
  10pt  tiny 5/6  scriptsize 7/8  footnotesize 8/9.5  small 9/11
        large 12/14  Large 14/18  LARGE 17/22  huge 20/25  Huge 25/30
  11pt  … small 10/12  large 12/14  Large 14/18  huge 20/25  Huge 25/30
  12pt  … small 11/13.6  large 14/18  Large 17/22  LARGE 20/25  huge/Huge 25/30

Layout impact is MIXED, not a clear win. On the -layout harness (40 papers, seed
1, tectonic ground truth) the mean divergence moves 7.760 -> 8.377 and the total
page-count error 123 -> 133 — a net REGRESSION driven almost entirely by ONE
algorithm2e paper (2508.20008, whose \SetCommentSty is only partly supported):
excluding it the mean improves 7.929 -> 7.879. Heading-heavy papers gain (one
13.76 -> 6.29), while caption/footnote/small-heavy papers lose a little, because
the engine already packs denser than tectonic and correct sizing amplifies that
pre-existing line-break/page-build divergence. This lands the correctness fix;
the layout metric will reward it once dense-region breaking matches tectonic.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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