Skip to content

render-pipeline: a run of math characters keeps its last italic correction - #461

Merged
GoKubar merged 1 commit into
mainfrom
agent/kabir-claude/math-text-italic-correction
Sep 14, 2026
Merged

GoKubar merged 1 commit into
mainfrom
agent/kabir-claude/math-text-italic-correction

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Stacked PR 1 of 3 (math detail, lane nixos-math-detail). Base: main.
Next: \limsup/\liminf thin space, then math \ldots/\cdots.

Mechanism

tex.web §752 leaves the last math_char of a run its delta. §753's
make_ord demotes a character to a math_text_char — which loses the
correction as "dubious" — only when the next noad is a math char of the
same family. In l i m that is true of l and i and false of m, so m
keeps its correction:

\setbox0=\hbox{$\lim$}\showbox0
.\hbox(8.38399+0.0)x16.3773
..\kern 0.0  ..l  ..i  ..m  ..\kern0.05731

shape_run already computed that value and then threw it away:

let italic = if key.is_some() { last_italic } else { 0.0 };

key is the math-alphabet font key, so the correction survived only for
\mathbf/\mathsf-style runs. The gate is the construct, not the font:
\lim and \mathrm{lim} are set in the same face as \text{lim} and still
measure 16.3773 pt against its 16.31999 pt.

Which Nucleus::Text atoms are whole runs of math characters is now re-read
from the control word at the atom's span (math_text_keeps_italic), the same
idiom fence_of / class_override_of / operator_limits_of already use.

math-layout needed no change: make_text already appends last_italic as a
kern and already returns δ = 0 for a Nucleus::Text nucleus — which is what
make_op does for a sub_mlist, so the Rule 13a limits are correctly not
shifted by δ/2. Verified against the oracle: both limit boxes of
$\lim\limits^{|}_{|}$ have identical glue and no shift.

Why a whitelist and not a blacklist

The first version of this read the control word to exclude \text and
\tag. That is wrong, and the suite caught it. A third kind of
Nucleus::Text looks exactly like a whole run and must behave like an
\hbox: the compiler emits a multi-character siunitx unit as one
Nucleus::Text per character
(siunitx.rs upright: "One character is one
upright run; several are a boxed group of one-character runs"), so
\unit{\katal} arrives as three runs k, a, t where TeX has a single
\mathrm{kat}. Correcting each of them puts an italic correction inside a
word — precisely what §752's math_text_char rule exists to prevent.

Measured: 12-unit-derived-c.tex moved 1.255 bp under the exclusion
version (siunitx_fixtures_match_pdflatex failed); it passes under the
whitelist. \mathrm{kat} and \mathrm{k}\mathrm{a}\mathrm{t} are
byte-identical in pdfTeX, which is the same fact from the other side.

Known under-application: a \operatorname{...} body, whose runs are built
from individual characters and so carry no control word at their span.

Oracle

TeX Live 2025 pdflatex under the harness preamble (12pt, T1, lmodern,
margin=1in, \parindent=0pt), read with \showbox, not from the PDF:
pdfTeX rounds a kern to 1/1000 em when it writes the content stream (0.012 bp
at 12 pt), a fifth of the effect being measured. pdflatex is an oracle only
and is never in the product path.

\mathrm{...} \text{...} difference
lim 16.3773 pt 16.31999 pt 0.05731 (m)
f 4.43732 pt 3.59024 pt 0.84708 (f)
det 16.3193 pt 16.3193 pt 0 (t has none)

Regression test

crates/render-pipeline/tests/math_text_italic_correction.rs. On main:

`\mathrm{lim}` keeps its last character's italic correction: 16.2590 bp, pdflatex 16.3161 bp (off by -0.0571)
`\lim x`: the word, its correction, then the Op thin space: 18.2515 bp, pdflatex 18.3086 bp (off by -0.0571)
`\mathrm{f}` carries f's 0.84708 pt correction: 3.5768 bp, pdflatex 4.4207 bp (off by -0.8439)

The fourth test (\bmod) passes on main and is a guard: d has no correction,
and the \kern0.32639 in that box is ec-lmr12's own (LABEL C o)(KRN C d R 0.0272) lig/kern pair, not an italic correction.

Corpus

tools/visual-oracle/rank.py, 22 fixtures / 59 pages, 15120 aligned words.
Within 0.5 bp: unchanged (dx 87.63%, dy 77.52%, both 72.28%) — the
correction is ~0.057 bp, far below that bucket. Total |dx| 38497.75 →
38486.30 bp
, on inline-math p1 (−9.256), twelvept-plain p2 (−1.300) and
inline-math p2 (−0.891); every page toward the oracle, none away.

Gates

render-pipeline suite green (exit 0), amsmath 59/59, tabular 106/106, corpus
22/22 fixtures with no page-count mismatch and no producer failure, zero
font-FAILURE diagnostics. Nothing under crates/render-pipeline/vendor/ is
touched; this is pipeline-only and needs no re-pin.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

…ction

tex.web §752 leaves the last `math_char` of a run its `delta`; §753's
`make_ord` demotes only a character whose *next* noad is a math char of the
same family, so the `m` of `l i m` keeps its correction and pdfTeX's `\lim`
box is `l i m \kern0.05731` -- 16.3773 pt against the 16.31999 pt of
`\text{lim}`, whose `\hbox` has none.

`shape_run` computed that correction and then discarded it for every run
without a math-alphabet font key, so `\lim`, `\mathrm{...}` and `\bmod` were
set at bare advances. The gate was the font; it should be the construct.
Which `Nucleus::Text` atoms are whole runs of math characters is re-read from
the control word at the atom's span (`math_text_keeps_italic`), the idiom
`fence_of` / `class_override_of` / `operator_limits_of` already use.

It is a whitelist rather than a blacklist because a third case looks exactly
like a whole run and must behave like an `\hbox`: the compiler emits a
multi-character siunitx unit as one `Nucleus::Text` per character, so
`\unit{\katal}` arrives as three runs where TeX has one `\mathrm{kat}`.
Correcting each of those adds a correction *inside* a word -- measured, it
moved `12-unit-derived-c.tex` by 1.255 bp.

Oracle: TeX Live 2025 pdflatex under the harness preamble, read with
`\showbox` rather than from the PDF, because pdfTeX rounds a kern to 1/1000 em
in the content stream (0.012 bp at 12 pt) -- a fifth of the effect measured
here. pdflatex is an oracle only and is never in the product path.

Corpus (tools/visual-oracle/rank.py, 22 fixtures / 59 pages): total |dx| over
15120 aligned words 38497.75 -> 38486.30 bp, on inline-math p1/p2 and
twelvept-plain p2, every page toward the oracle and none away. No word crosses
the 0.5 bp bucket, because the correction is about 0.057 bp.

Gates: render-pipeline suite green, amsmath 59/59, tabular 106/106, corpus
22/22 fixtures with no page-count mismatch, zero font-FAILURE diagnostics.

Implementation-Agent: Claude Opus 5 (lane nixos-math-detail, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
@GoKubar
GoKubar merged commit a5e904d into main Sep 14, 2026
21 checks passed
@GoKubar
GoKubar deleted the agent/kabir-claude/math-text-italic-correction branch September 16, 2026 04:17
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