Skip to content

render-pipeline: lay out T1 cmr documents with EC metrics (HW1 breaks = pdflatex) - #111

Merged
jay3332 merged 1 commit into
mainfrom
agent/kabir-claude/hw-text-widths
Sep 13, 2026
Merged

jay3332 merged 1 commit into
mainfrom
agent/kabir-claude/hw-text-widths

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Why HW1/HW2 line breaks differed

All nine fixtures/real-world documents use \usepackage[T1]{fontenc} without lmodern. So pdflatex sets them in LaTeX's default t1cmr.fd fonts, which use the EC metrics (ecrm1095 for 11pt body text, ecbx1200, ...). The pipeline laid them out with ec-lm* metrics (ec-lmr10 scaled to 10.95pt) instead.

Delta source Size Effect
ec-lmr10@10.95 vs ecrm1095 widths about +0.57% (ecrm1095 QUAD 0.994328, SPACE 0.331557 vs 0.333333) about 2.7pt over a 470pt line; moves HW1 p1/p2/p3 and HW2 p1/p2 breaks
Interword glue same 0.57% (fontdimens 2-4 come from the TFM) included above
Kerns and ligatures same program shape; EC tables used now included above
\hsize / \parindent / \parshape 469.755pt, 0pt, none: already exact none
microtype (protrusion + expansion level 2) HW1: no break change. HW2: p3 line 3 ("odd, and") not wired, see below
Inline math widths HW2 p3 line 1: "for" (b=1) vs "every" (b=6) both feasible, pdflatex takes "for" on demerits remaining HW2 diff

A blocker sat under the metrics: the shared font-resources TFM reader rejected every jknappen/ec file with TFM file/table length mismatch. Those files are zero-padded to 3584 bytes, but TeX (tex.web §575) reads only lf words, and tftopl says "extra junk at the end ... proceed as if it weren't there".

Change (render-pipeline only, no vendor edits)

  • Family::ComputerModern: EC metrics with Latin Modern outlines. Chosen by Stylesheet::family_for for T1 fontenc without lmodern. OT1 and lmodern documents are unchanged.
  • ec_tfm_file: the declared sizes and shapes from t1cmr.fd, picking the nearest declared size.
  • FontSet::otf_with_tfm: one face entry per metric file. It keeps the same program and wire font_id but gets its own shape_key, so the shaper cache never mixes LM and EC runs. If the EC file is missing, the ec-lm TFM is used and an ec_metrics_unavailable warning is emitted.
  • TFM discovery appends <texmf>/fonts/tfm/jknappen/ec after all existing candidates, so existing order is unchanged.
  • Tfm::parse reads the header's lf words only.

Gates

Line breaks vs MacTeX pdflatex (differing hunks per page; \mathbb extraction artifacts ignored):

Document Per page Total
HW1 p1 1→0, p2 1→0, p3 1→0 3→0
HW2 p1 1→0, p2 1→0, p3 1→1 (math width, microtype) 3→1

Real-world corpus: 31 → 25 hunks; no fixture worse (letter 3→2, other six unchanged); page counts equal.

Overfull: counts identical on all 9 fixtures (HW1 0, HW2 1, article-twocolumn 1, lecture-notes 2).

Tests: cargo test --release in render-pipeline is green, including 7 new tests: padded TFM, ecrm1095 load, t1cmr.fd table, CM vs LM faces, EC fallback, discovery order, family_for/t1_encoding.

FT-065 perf_bench --steps 20: HW1/HW2 keystroke p50 within ±0.1ms of main (for example HW1 type-paragraph 1.12→1.04ms, HW2 1.12→1.15ms). The 500KB document's digests are byte-identical, since it is OT1. HW1/HW2 digests change as intended.

Follow-ups (not in this PR)

  • Mac bundle (apps/, not touched): ship jknappen/ec TFMs next to ec-lm*. Until then the app warns ec_metrics_unavailable and keeps today's LM metrics.
  • font-resources: relax bytes.len() != lf*4 to < in tfm.rs upstream, then drop the render-pipeline trim at the next re-pin.
  • Microtype: HW2 p3 line 3 needs expansion wired into the breaker (crates/microtype).
  • Math widths (mathbb lane): HW2 p3 line 1 is the \mathbb ℝ advance, taken from latinmodern-math rather than the msbm10 TFM: 0.91pt short per ℝ, 3 on the line. Every other chunk on that line matches pdflatex to within 0.005pt.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

Documents with \usepackage[T1]{fontenc} and no lmodern get LaTeX's
default t1cmr.fd fonts in pdflatex: the EC metrics (ecrm1095 for 11pt
body text), not the ec-lm* metrics lmodern selects. ec-lmr10 scaled to
10.95pt is about 0.57% wider (ecrm1095 quad 0.994328 of the size), which
moved line breaks in every real-world fixture (all nine are T1 without
lmodern).

- Family::ComputerModern: EC metrics with the Latin Modern outlines,
  selected by Stylesheet::family_for (T1 fontenc, no lmodern).
- ec_tfm_file: t1cmr.fd's declared sizes (5..35.83) and shapes
  (ecrm/ecbx/ecti/ecbi/ecsl), nearest declared size.
- FontSet::otf_with_tfm: a separate face entry per metric file (same
  program and wire font_id, own shape_key so the shaper cache does not
  mix LM and EC runs); a missing EC file falls back to the ec-lm TFM
  with an ec_metrics_unavailable warning.
- TFM discovery appends <texmf>/fonts/tfm/jknappen/ec after every
  Latin Modern candidate (order of existing entries unchanged).
- Tfm::parse reads only the header's lf words, as TeX (tex.web 575) and
  tftopl do: the jknappen/ec files are zero-padded to 3584 bytes and the
  shared font-resources reader rejected them ("file/table length
  mismatch").

HW1 line breaks now match pdflatex on all pages (3 -> 0 differing
hunks); HW2 3 -> 1 (p3 line 1, an inline-math width delta). Real-world
corpus 31 -> 25 break hunks, no fixture worse, overfull counts equal.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude HW text widths, 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
@jay3332
jay3332 merged commit 1c1e3f7 into main Sep 13, 2026
11 of 18 checks passed
@jay3332

jay3332 commented Sep 13, 2026

Copy link
Copy Markdown
Member

Merged to main via integration/2026-09-13h (Commander).

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