Skip to content

compiler: amsthm sets the whole theorem head in the head font - #196

Merged
GoKubar merged 1 commit into
mainfrom
agent/linux-primary/amsthm-head-font-compiler
Sep 13, 2026
Merged

GoKubar merged 1 commit into
mainfrom
agent/linux-primary/amsthm-head-font-compiler

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Finishes the first of the two amsthm items #190 left deliberately: the head's
trailing punctuation is emitted with the default style where amsthm sets it in
the head font
. The second (the head→body separator) is
#197, which is independent and also based on main.

Together they let #190 leave draft: with all three in place the fixture's
theorem heads are exact rather than merely close (numbers below).

What amsthm actually builds

\@begintheorem (amsthm.sty 2020/05/29):

\deferred@thm@head{\the\thm@headfont \thm@indent
  ... \thm@swap\swappedhead\thmhead{#1}{#2}{#3}%
  \the\thm@headpunct
  \thmheadnl
  \hskip\thm@headsep
}

Everything the head is made of is read inside \the\thm@headfont
(\bfseries, \itshape for remark) — the name, the space tokens between
its pieces
and the trailing punctuation. Exactly two things inside it are
not: \thmhead@plain wraps the note in \thm@notefont{\fontseries\mddefault \upshape} and the number in \@upn (\textup).

This crate emitted the . and the space before the note with
TextStyle::default(), and numbered an italic remark head in italics.

Measured, not read off the .sty

pdflatex, TeX Live 2025, oracle only, never in the product path.
\documentclass[11pt]{article} + [T1]{fontenc} + amsthm, \showboxbreadth=100 \showboxdepth=100 \tracingoutput=1. fixtures/real-world/lecture-notes' own
first head ships as:

\T1/cmr/bx/n/10.95 D e ^^\ (ligature fi) n i t i o n
\kern 0.0
\glue 4.17043 plus 2.08443 minus 1.3896       % the *bold* space
\T1/cmr/bx/n/10.95 1 . 1
\kern 0.0
\glue 4.17043 plus 2.08443 minus 1.3896       % bold again
\T1/cmr/m/n/10.95 ( D i v i d e s )           % \thm@notefont
\T1/cmr/bx/n/10.95 .                          % \the\thm@headpunct
\glue 5.0 plus 1.0 minus 1.0                  % \hskip\thm@headsep
\T1/cmr/m/n/10.95 L e t                       % the body

The body face's interword space is 3.63054 plus 1.81337 minus 1.20892, so the
two head spaces are 0.54 pt wider each than what we were emitting. A numbered
remark ships as italic R e m a r k, \kern 1.17863, \glue 3.91763 plus 1.67899 minus 1.11932 (italic), \OT1/cmr/m/n/10.95 1, \OT1/cmr/m/it/10.95 .
— italic name, italic space, upright number, italic period.

The change

  • the head punctuation takes the head style;
  • the space before the note is its own head-styled run, and the note itself
    stays upright medium;
  • a number whose \@upn shape differs from the head's — only a remark — is
    its own upright run. Where \@upn is a no-op the name and number stay one
    run, so nothing else in the tree moves.

proof already emitted Proof. as one italic run, which is what
\item[\hskip\labelsep \itshape #1\@addpunct{.}] produces; a test now pins it.

Gates

crates/compiler, cargo test --release --no-fail-fast: 446 passed, 0
failed
against a control checkout of the same base (9abbf330) at 444
passed, 0 failed
— same set, +2 = the tests added here.

Real-world corpus through the render pipeline, with this crate patched into
crates/render-pipeline/vendor/compiler (locally, not committed) so the
effect is measurable at all: nine of ten fixtures byte-identical to an
origin/main control (hw1, hw2, cv, inline-math, input-bibliography, letter,
math-sheet, unicode-accents, article-twocolumn), lecture-notes the only one
that moves, with byte-identical diagnostics (8, no font substitution, 0
overfull) and unchanged page counts. amsmath oracle corpus 59/59 within
0.5 bp. Bundled apps/mac/Fonts with the explicit FLASHTEX_TFM_DIRS
spelling that reaches the rooted metrics reader; never the system TeX Live.

lecture-notes word geometry against the committed reference.pdf
(difflib-aligned words, |dx| in bp, 419 aligned words in every row):

build median |dx| ≤0.01 bp ≤0.1 bp ≤0.5 bp lines
main 7.6051 116 125 138 32/56
+ this PR (vendored) 7.6051 116 125 138 32/56
+ #190 0.1366 174 199 285 38/56
+ #190 + #197 0.0305 199 245 340 38/56
+ #190 + #197 + this PR 0.0048 235 284 339 38/56

This PR changes nothing measurable on its own, by design. Without #190 the
pipeline reads a theorem's weights from the source's brace groups, not from
this crate's scoping, so a bold period here is simply not consulted; the
lecture-notes display list differs only in run structure. That is also why it
is safe to land in any order.

On the fixture's Definition 3.1. line, body start against the oracle's
155.3717 bp: main + #190 155.8772 (+0.5055), with #197 instead 154.9534
(−0.4183), with both 155.3744 (+0.0027) — and the rest of that line then
lands inside 0.06 bp. Two errors of opposite sign again, exactly as #190 warned;
neither PR should be judged alone on this fixture.

Left, with the measurement that says why

  • the head→body separator — \hskip\thm@headsep = \glue 5.0 plus 1.0 minus 1.0, and for proof \@item's trailing \hskip\labelsep (5.475 pt
    rigid at 11pt). Inline has no rubber horizontal glue (HSpace is fixed),
    and the consumer that also has to stop deriving an interword space from the
    source gap at that point is the render pipeline, which reads this crate
    through its pinned vendor/compiler. Adding an inline here would reach the
    product only at the next vendor re-pin and, until the pipeline stopped
    deriving its own space, would be doubled. It is render-pipeline: the amsthm head separator is the package's glue, not a space #197 that lands it.
  • the \kern 1.17863 italic correction \@upn inserts in a remark head.
  • \@addpunct's "no second period when the heading already ends in one" test,
    for proof's optional heading (\begin{proof}[Proof of Lemma 2.]).

No committed oracle data was regenerated — this box is TeX Live 2025, not
MacTeX. Nothing under crates/render-pipeline/vendor/ is committed.

Merge order

Independent of #190 and #197; lands in any order. The fixture only becomes
exact once #190 → this PR's next vendor re-pin → #197 are all in (the
first two are what make the bold period visible at all).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

`\@begintheorem` builds the head as

    \the\thm@headfont \thm@indent <name> <number> <note> \the\thm@headpunct

so everything the head is made of -- the name, the space tokens between its
pieces and the trailing punctuation -- is read in `\thm@headfont`
(`\bfseries`, `\itshape` for `remark`). Only two things inside it are not:
the note, which amsthm wraps in `\thm@notefont{\fontseries\mddefault
\upshape}`, and the number, which `\thmhead@plain` wraps in `\@upn`
(`\textup`).

This crate emitted the trailing `.` and the space before the note with
`TextStyle::default()`, i.e. from the body font, and numbered an italic
`remark` head in italics.

Measured against pdflatex (TeX Live 2025, oracle only, never in the product
path), `\documentclass[11pt]{article}` + `[T1]{fontenc}` + amsthm with
`\tracingoutput=1`. `fixtures/real-world/lecture-notes`' own first head
ships as

    \T1/cmr/bx/n/10.95 D e ^^\ (ligature fi) n i t i o n
    \kern 0.0
    \glue 4.17043 plus 2.08443 minus 1.3896       % the *bold* space
    \T1/cmr/bx/n/10.95 1 . 1
    \kern 0.0
    \glue 4.17043 plus 2.08443 minus 1.3896       % bold again
    \T1/cmr/m/n/10.95 ( D i v i d e s )           % \thm@notefont
    \T1/cmr/bx/n/10.95 .                          % \the\thm@headpunct
    \glue 5.0 plus 1.0 minus 1.0                  % \hskip\thm@headsep
    \T1/cmr/m/n/10.95 L e t                       % the body

and a numbered `remark` as italic `R e m a r k`, `\kern 1.17863`,
`\glue 3.91763 plus 1.67899 minus 1.11932` (italic), `\OT1/cmr/m/n/10.95 1`,
`\OT1/cmr/m/it/10.95 .`.

So: the head punctuation now takes the head style, the space before the note
is emitted as its own head-styled run (the note itself stays upright medium),
and a number whose `\@upn` shape differs from the head's -- only a `remark` --
becomes its own upright run. Where `\@upn` is a no-op the name and number stay
a single run, as before.

Not changed here, with the measurement that says why:

* the head-to-body separator (`\hskip\thm@headsep`, `\glue 5.0 plus 1.0
  minus 1.0`; `proof` instead gets `\@item`'s trailing `\hskip\labelsep`,
  5.475pt rigid at 11pt). `Inline` has no rubber horizontal glue -- `HSpace`
  is fixed -- and the consumer that has to stop deriving an interword space
  from the source gap at that point is the render pipeline, which reads this
  crate through `crates/render-pipeline/vendor/compiler`. It is the pipeline
  change that lands it (see the companion PR); adding a new inline here would
  only reach the pipeline at its next vendor re-pin, and until then would be
  either invisible or doubled.
* the `\kern 1.17863` italic correction `\@upn` inserts in a `remark` head,
  and `\@addpunct`'s "no second period when the heading already ends in one"
  test for `proof`'s optional heading.

`crates/compiler`: 443 passed, 0 failed (441 on the base + the two new tests).
No committed oracle data was regenerated; this box is TeX Live 2025.

Implementation-Agent: engine-engineer (Claude Opus 5), linux-primary
Commit-Executor: engine-engineer (Claude Opus 5), direct git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
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