Skip to content

render-pipeline: squeeze too-wide displays, numbers on their own line, subequations label line (display-placement 33/36; needs #148 + #155 re-pin, includes #146) - #157

Merged
jay3332 merged 3 commits into
mainfrom
agent/kabir-claude/display-too-wide
Sep 13, 2026
Merged

jay3332 merged 3 commits into
mainfrom
agent/kabir-claude/display-too-wide

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Part C of the display-math blockers left by #146. It includes #146's branch (merged in, #146 is not on main yet). It builds only after vendor/math-layout is re-pinned to #148 and vendor/compiler to #155. No vendor edits in this PR.

What (tex.web §1199-§1205, typeset.rs/adapter.rs)

  • display_block: a formula too wide beside its number is packed to z - q with math-layout's MathBox::pack_to when its shrink reaches (or any infinite shrink exists). Otherwise the number goes on its own line: \eqno below with no \belowdisplayskip, \leqno above with no \abovedisplayskip, joined by \penalty10000. The formula alone is packed to z if it is still too wide, and d = 0 when it starts with glue. The overfull warning reports what the shrink cannot absorb.
  • layout_kerned builds one flat hlist: each run's list is spliced in, and the spacing across a \quad split becomes muskip glue, so glue_totals sees every glue of the formula. Positions are unchanged.
  • Equation numbers and \tag labels are an \hbox of words with natural interword glue (\maketag@@@). Before, they were one shaped run with T1's visible-space glyph, so a spaced tag was 1.67pt too wide per space.
  • A \label left in horizontal mode after a display (\begin{subequations}\label{..}) is set as an empty line before the next display, as TeX's line_break does for a whatsit-only list.

Evidence (uncommitted scratch copy: vendor math-layout = #148, vendor/compiler = the #146 pin plus #155's parser/xref/supported diff)

  • display-placement oracle: 33/36 (render-pipeline: display math placement (leqno, fleqn, \eqno, \tag*, after headings, lists; oracle 19→29/36) #146 alone: 29). Now passing: 09, 10, 18, 33.
  • Fixture 17: the numbers are right ((1.1), (2.1)). It still fails by 0.78bp at \eqref: LaTeX's \sw@slant (latex.ltx 14268-14290, confirmed by \showlists: \kern0.7922 before the space) adds the preceding f's italic correction before any upright \text… command. That is a general text-font rule for the text/HW lane, not display math.
  • 15 (\tag{$..$}) and 20 (nested list labels) are out of scope.
  • amsmath corpus: 42/42.
  • cargo test --release (render-pipeline): 146 passed, 1 ignored, 0 failed. tests/display_placement.rs now also covers 09, 10, 18 and 33.
  • HW1, HW2, math-sheet, lecture-notes, article-twocolumn, cv, letter, unicode-accents and input-bibliography produce byte-identical --v2 output to the same build without this commit.
  • fixtures/display-placement/baseline-render-pipeline.json is refreshed to 33/36.

Re-pin order

  1. math-layout: TeX stretch/shrink on math glue and hpack-exact pack_to (display-math blocker 1 of #146) #148 (math-layout)
  2. compiler: \numberwithin, \counterwithin and subequations on one counter table (display-math blocker 2 of #146) #155 (compiler)
  3. Re-pin vendor/math-layout and vendor/compiler. vendor/compiler on main is behind crates/compiler; the render-pipeline: display math placement (leqno, fleqn, \eqno, \tag*, after headings, lists; oracle 19→29/36) #146 pipeline does not build against main's newer compiler (Inline::Logo/Rule/Kern, Nucleus::Rule), so the integrator's usual re-pin covers that.
  4. render-pipeline: display math placement (leqno, fleqn, \eqno, \tag*, after headings, lists; oracle 19→29/36) #146
  5. This PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

GoKubar and others added 3 commits September 13, 2026 08:23
…no, \tag*, after headings, lists; oracle 29/36)

Display rules of TeX 1145/1199-1205 and amsmath's \mathdisplay, measured
by a new 36-fixture pdflatex oracle (fixtures/display-placement; main 19/36):

- amsmath leqno: numbers left, normal skips (1203); fleqn: formula at
  \@mathmargin, tags per \emdf@R/\emdf@L; align/gather under both.
- primitive $$ ... \eqno/\leqno $$ numbers (read from source).
- \tag* without parentheses; counter numbers formatted in the adapter.
- a display right after a heading sets no empty line (1145).
- text after a display carrying \label, and displays inside quote and
  list items, continue the paragraph (no indent, short skips).
- the short-skip test is d + s <= \predisplaysize, not a too-wide flag.

Not yet: glue shrink of too-wide formulas (math-layout glue has no shrink),
\numberwithin/subequations (compiler counter), \tag{$..$}, nested list
labels. amsmath corpus 42/42; HW1/HW2 byte-identical to main.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude display math placement, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…display-too-wide

C wires math-layout pack_to (#148) and compiler numbering (#155) into the
display placement of #146, which is not merged yet.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude math glue + numbering, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
…their own line, label lines (display-placement 33/36)

tex.web 1199-1205 in display_block, on math-layout's MathBox::pack_to:

- a formula wider than \displaywidth beside its number is set with
  hpack(p, z - q, exactly) when its shrink reaches (or any infinite shrink
  exists); otherwise the number goes on a line of its own (\eqno below the
  formula without \belowdisplayskip, \leqno above it without
  \abovedisplayskip, kept together by \penalty10000) and the formula alone
  is packed to z if still too wide; d is 0 when the formula starts with
  glue. Overfull displays are reported by the amount the shrink cannot
  absorb.
- layout_kerned splices each run's hlist into one flat list and sets the
  spacing across a \quad split as muskip glue, so glue_totals sees every
  glue of the formula (positions unchanged).
- equation numbers and \tag labels are an \hbox of words with natural
  interword glue (\maketag@@@), not one shaped run with T1's visible-space
  glyph (a spaced \tag was 1.67pt per space too wide).
- a \label left in horizontal mode after a display (\begin{subequations}
  \label{..}) is set as an empty line before the next display, as TeX's
  line_break does with a whatsit-only list (predisplaysize -\maxdimen).

Depends on #148 (math-layout pack_to, glue stretch/shrink) and #155
(compiler \numberwithin/subequations): it builds only once vendor/
math-layout and vendor/compiler are re-pinned to them. Merges #146 (not yet
on main).

Verified in an uncommitted scratch copy (vendor math-layout = #148,
vendor/compiler = the #146 pin plus #155's parser/xref/supported diff):
display-placement oracle 33/36 (was 29; now 09, 10, 18, 33 pass; 17's
numbers are right but \eqref misses LaTeX's \sw@slant italic correction
before its space, 0.78bp; 15 and 20 out of scope); amsmath corpus 42/42;
cargo test --release 146 passed, 0 failed; HW1, HW2 and the seven other
real-world fixtures produce byte-identical v2 output to the same build
without this commit.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude math glue + numbering, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar added a commit that referenced this pull request Sep 13, 2026
Kept #157's label-only empty line before a display together with main's stretched_left predisplaysize. The merge log also records why #145 was aborted rather than merged.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude integration, nixos-pc-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar added a commit that referenced this pull request Sep 13, 2026
Clean merge; supplies MathBox::tag throughout. #157's new squeezed-display MathBox literal takes SourceTag::NONE, like #165's synthetic glue.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude integration, nixos-pc-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar added a commit that referenced this pull request Sep 13, 2026
16 conflicts (adapter.rs 10, typeset.rs 5, incremental.rs 1). All but one were
misalignments: git shared common tails between this branch's additions and
#156's, so each side ended mid-construct and a plain "keep both" would not
compile. Rebuilt as complete separate pieces, as the merge log records for
#154 and #170.

- `Item` / `BoxRec` / `AItem` / `Paragraph`: both sides add variants and
  fields (#156's Glue, Rigid, Penalty, EmptyBox, Qed, Rules, LocalRule,
  `theorem_head`). Kept from both, with the enclosing enum, struct and match
  arms closed explicitly where git had shared a brace.

- **Incremental cache tags renumbered.** #156 numbered its five new
  `hash_items` arms 10-14, which this branch already uses for
  Footnote/TextBox/SetLength/LengthGlue/HSs. These tags key the incremental
  layout cache, so a collision serves one item's cached layout for another --
  the same hazard #170 hit, fixed the same way. #156's are now 19-23, the
  first free run. The two pre-existing collisions (Logo/Table at 9,
  Footnote/Rule at 10) are left for #182, which replaces the hand-numbering
  with `mem::discriminant`.

- `\qedhere` in a display: #156's block computes e/q before the display is
  placed, so it goes ahead of #157's fleqn/§1201 squeeze rather than the
  plain §1199 centring #156 carried with it. The symbol is built into a
  `NumberBox` (this branch's representation, which is where display_block
  reads the height and depth from) instead of #156's bare `(run, rec)` pair.

- `\addvspace`: kept main's `\@xaddvskip` rule (a negative amount after a
  non-negative `\lastskip` is added to it) together with #156's flex, so the
  surviving skip keeps its own stretch and shrink.

- `gap_has_list_end` came back. The origin/main merge had dropped it as
  having no caller; #156's theorem-skip code needs it. It is now written in
  terms of `LIST_ENVS` so it cannot drift from the other list predicates.

The one real disagreement, found by measurement, not by reading

#156 guards display continuation with `*prev_style == ParaStyle::Plain &&
prev_list.is_none()`. Merged as written, display-placement fell from 33/36 to
31/36: every new failure was a display inside a list or a quote, shifted 12
to 20 pt vertically (`20-enumerate-nested-display`, `29-quote-display`, and
`19-itemize-display` got worse).

Those two conjuncts are #156's older, coarser form of two conditions this
branch already states more precisely two lines above -- `same_list` (which
compares level and margins, not merely "no list") and `styled.unwrap_or_
default() == *prev_style`. Keeping them disabled display continuation inside
every list. Only `&& !theorem_head`, the genuinely new theorem condition, is
kept; display-placement is back to 33/36.

Gates (NixOS PC, TeX Live 2025, bundled tree plus nix-store `ec`; no
committed oracle data regenerated; zero font diagnostics on every run):

- amsmath 59/59, tabular 59/59, display-placement 33/36 -- all unchanged.
- theorem_oracle passes (#156's own corpus, MacTeX references).
- real-world 10/10 recovered, every page count still equal to its committed
  reference. lecture-notes drops from 7 diagnostics to 6: a theorem construct
  that was recovered is now supported.
- `cargo test --release` in render-pipeline: the same 11 known failures as
  before this merge, no more. Eight of them also fail on unmerged
  origin/main on this machine (the four NewCM controls, metrics_provenance,
  font_families_oracle, footnotes_oracle, page_frame); the other three
  (float_bodies, headings, list) have no baseline on a non-MacTeX host.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude integration, nixos-pc-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@jay3332
jay3332 merged commit 6e1d8a1 into main Sep 13, 2026
12 of 18 checks passed
@GoKubar
GoKubar deleted the agent/kabir-claude/display-too-wide branch September 13, 2026 18:12
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.

2 participants