Skip to content

render-pipeline: math \ldots and \cdots are \mathinner of three Punct dots - #463

Closed
GoKubar wants to merge 3 commits into
agent/kabir-claude/limsup-thin-spacefrom
agent/kabir-claude/math-ellipsis
Closed

GoKubar wants to merge 3 commits into
agent/kabir-claude/limsup-thin-spacefrom
agent/kabir-claude/math-ellipsis

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Stacked PR 3 of 3 (math detail, lane nixos-math-detail). Base:
agent/kabir-claude/limsup-thin-space (#462) — review #461 and #462 first;
this diff is only the third commit. This is the one with the corpus win.

Mechanism

\mathellipsis and \cdots are \mathinner{\dotp\dotp\dotp} of a
punctuation atom. That is two facts about spacing, neither of which an
ordinary atom has:

  • Punct against Punct is a thin space, so the three dots sit 3mu apart;
  • \mathinner is the Inner class, so the group takes a thin space against
    the Ord on each side
    .

The compiler flattens both to three bare characters — Nucleus::Text("...")
for the low dots, Nucleus::Symbol("⋅⋅⋅") for the centred ones — so the atoms
are rebuilt from the control word at the atom's span (math_ellipsis_of), the
idiom fence_of / class_override_of / operator_limits_of already use.

A correction to how this was scoped

This was handed to me as compiler-side work needing a vendor re-pin. It does
not: the glyphs were already right.
flashtex_math_layout::cm::symbol_slot maps . to math italic "3A
(\ldotp) and U+22C5 to cmsy "01 (\cdotp), exactly as plain TeX's
\mathcodes do. What was wrong is that the low dots never reached that
table — Nucleus::Text goes to the text-font run path, so they were set in
ec-lmr12 — and that neither form had any of the four thin spaces.

Those four spaces are essentially the entire error: the two periods differ by
under 0.0001 bp in width (roman . 3.2518 bp, cmmi . 3.2517 bp). So this
is a pipeline-only change, it lands now, and it does not wait on
agent/kabir-claude/vendor-repin-par-leading.

Oracle

TeX Live 2025 pdflatex under the harness preamble, \showbox / \showthe\wd.
pdflatex is an oracle only and is never in the product path.

\setbox0=\hbox{$a\ldots b$}          \setbox0=\hbox{$a\cdots b$}
.a                                   .a
.\glue(\thinmuskip) 1.99997          .\glue(\thinmuskip) 1.99997
.\hbox(1.16666+0.0)x13.7915          .\hbox(5.33334+0.0)x13.99997
..\OML/lmm/m/it/12 :  (x3, 3mu)      ..\OMS/lmsy/m/n/12 ^^A  (x3, 3mu)
.\glue(\thinmuskip) 1.99997          .\glue(\thinmuskip) 1.99997
.b                                   .b

\wd $\ldotp$ 3.26385 pt, \wd $\cdotp$ 3.33334 pt, \thinmuskip 1.99997 pt.

Regression test

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

`\ldots`: dot to dot: 3.2518 bp, pdflatex 5.2442 bp (off by -1.9923)
`\cdots`: dot to dot: 3.3209 bp, pdflatex 5.3134 bp (off by -1.9925)
`\dots` is the low dots: 3.2518 bp, pdflatex 5.2442 bp (off by -1.9923)
`\ldots` opens with the Inner thin space: 0.0000 bp, pdflatex 1.9925 bp (off by -1.9925)

vdots_and_ddots_are_left_alone passes on main and is a guard.

Corpus

tools/visual-oracle/rank.py, 22 fixtures / 59 pages. Within 0.5 bp:

main this stack
dx 87.63% 88.87% (+194 words)
dy 77.52% 77.55% (+11)
both 72.28% 73.53% (+194)
aligned words 15120 15128
total |dx| 38497.75 bp 34978.92 bp

Every changed page improved; none regressed on any metric. Biggest movers:

page dx within 0.5 mean |dx| max |dx|
thesis-chapter p3 438 → 487 2.324 → 0.053 426.27 → 3.61
hw2 p3 86 → 109 0.729 → 0.054 5.51 → 1.16
inline-math p1 551 → 641 5.580 → 2.527 —
conf-paper p2 640 → 652 0.048 → 0.002 2.49 → 0.005
twelvept-plain p2 247 → 260 0.113 → 0.008 2.00 → 0.13
twelvept-plain p1 158 → 163 0.062 → 0.003 2.70 → 0.009

(The +194/+8 are this PR; #461 contributes −11.45 bp of total |dx| and no
bucket change, #462 none — the 22 fixtures have no \limsup/\liminf.)

What this deliberately does not do

  • amsmath's context-sensitive \,. amsmath redefines \cdots,
    \dotsb, \dotsm, \dotsc and \dotso through \extrap@ (amsmath.sty
    612–628) to append a 3mu \, when the next token is ,, ;, . or a
    \DOTSB operator. Measured: $a\cdots ,b$ minus $a,b$ is 19.99987 pt
    where $a\cdots b$ minus $ab$ is 17.99991 — one extra thin space. Neither
    the pinned compiler nor this change reads the following token, so that \,
    is still missing. The corpus does contain such uses (\cdots + three
    times), and those pages still improve substantially — hw2 p3's residual
    max |dx| is 1.16 bp. The kernel's \ldots is not redefined and is
    unaffected ($a\ldots ,b$ minus $a,b$ equals $a\ldots b$ minus $ab$).
  • \vdots and \ddots. They are not runs of math dots but \vbox
    constructions over text-font periods — \vdots is a \vbox of three
    \hbox{.} at \baselineskip 2.83334 over a \kern 6.0; \ddots is an
    Inner hbox of three \hbox{.} shifted −7.0/−4.0/−1.0 between kerns of
    0.66666 and 1.33331. math-layout has no atom that builds a vbox, so they
    need their own change. vdots_and_ddots_are_left_alone pins that this
    change did not reach them.

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.

🤖 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)
They are the only two of the kernel's thirty-odd log-like functions whose
definition is not a single word (latex.ltx 15528-15529):

    \DeclareRobustCommand\limsup{\mathop{\operator@font lim\,sup}}
    \DeclareRobustCommand\liminf{\mathop{\operator@font lim\,inf}}

The compiler has no glue inside a named operator and emits one
`Nucleus::Text("limsup")`, so the `\,` is lost. It is re-derived from the
control word at the atom's span (`operator_thin_space_split`) and the operator
becomes `lim` + 3mu + `sup`, as an Op atom whose nucleus is that list -- which
is also what TeX has, so `make_op`'s delta stays 0 and the Rule 13a limits are
not shifted.

Splitting the word also earns `lim` its own italic correction: its `m` is now
followed by glue rather than by a math character of the same family, so §753's
`make_ord` never demotes it to a `math_text_char`. pdfTeX's box is
`l i m \kern0.05731 \glue 1.99997 s u p`, so the gap from `m` to `s` is
2.05728 pt -- a fix that inserted only the thin space would still be 0.057 pt
short. `\liminf` likewise closes with `f`'s `\kern0.84708`.

Oracle: TeX Live 2025 pdflatex under the harness preamble, `\showbox`.
pdflatex is an oracle only and is never in the product path.

No corpus effect: the 22 fixtures contain no `\limsup` or `\liminf`. The fix
is carried by the oracle numbers and the new regression test, which fails on
main by exactly -2.0496 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)
… Punct dots

`\mathellipsis` and `\cdots` are `\mathinner{\dotp\dotp\dotp}` of a
*punctuation* atom, which is two facts about spacing that an ordinary atom
does not have: Punct against Punct is a thin space, so the three dots sit 3mu
apart, and the Inner class takes a thin space against the Ord on each side.

The compiler flattens both to three bare characters -- `Nucleus::Text("...")`
for the low dots, `Nucleus::Symbol("...")` for the centred ones -- so the atoms
are rebuilt from the control word at the atom's span (`math_ellipsis_of`), the
idiom `fence_of` / `class_override_of` / `operator_limits_of` already use.

The glyphs were already right: `flashtex_math_layout::cm::symbol_slot` maps
`.` to math italic "3A (`\ldotp`) and U+22C5 to cmsy "01 (`\cdotp`) exactly as
plain TeX's `\mathcode`s do. What was wrong is that the low dots never reached
that table -- `Nucleus::Text` goes to the text-font run path, so they were set
in ec-lmr12 -- and that neither form had any of the four thin spaces. Those
four are essentially the whole error: the two periods differ by under
0.0001 bp in width.

Oracle: TeX Live 2025 pdflatex under the harness preamble, `\showbox` and
`\showthe\wd`. `$a\ldots b$` is `a | thin 1.99997 | hbox 13.7915 | thin
1.99997 | b`. pdflatex is an oracle only and is never in the product path.

Corpus (tools/visual-oracle/rank.py, 22 fixtures / 59 pages): within 0.5 bp,
dx 87.63% -> 88.87% (+194 words), dy 77.52% -> 77.55%, both 72.28% -> 73.53%;
aligned 15120 -> 15128; total |dx| 38497.75 -> 34978.92 bp. thesis-chapter p3
(dx_max 426.27 -> 3.61) and hw2 p3 (5.51 -> 1.16) gain the most, with
conf-paper p2, twelvept-plain p1/p2, inline-math p1, hw2 p2, math-sheet p2 and
enumitem-worksheet p1 also improving. No page regressed on any metric.

Not modelled: amsmath redefines `\cdots`/`\dotsb`/`\dotsm`/`\dotsc`/`\dotso`
through `\extrap@` (amsmath.sty 612-628) to append a 3mu `\,` when the next
token is `,`, `;`, `.` or a `\DOTSB` operator -- measured, `$a\cdots ,b$` is
one thin space wider than this produces. Neither the pinned compiler nor this
change reads the following token. The kernel's `\ldots` is not redefined and is
unaffected. `\vdots` and `\ddots` are deliberately left alone: they are `\vbox`
constructions over *text*-font periods, not runs of math dots, and math-layout
has no atom that builds a vbox; a regression test pins that they are untouched.

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 force-pushed the agent/kabir-claude/limsup-thin-space branch from f4b438c to f818952 Compare September 14, 2026 20:00
@GoKubar
GoKubar deleted the branch agent/kabir-claude/limsup-thin-space September 14, 2026 20:04
@GoKubar GoKubar closed this Sep 14, 2026
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