Skip to content

fonts: bundle the typewriter metrics and outlines \texttt needs - #183

Merged
GoKubar merged 2 commits into
mainfrom
agent/kabir-claude/bundle-typewriter-fonts
Sep 13, 2026
Merged

GoKubar merged 2 commits into
mainfrom
agent/kabir-claude/bundle-typewriter-fonts

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Based on main 89e49fed, not stacked. apps/mac/Fonts + one new render-pipeline test; no vendor edits, no compiler changes.

The problem

apps/mac/Fonts carried no typewriter design at all — no ectt/ecst/ecit/ectc under jknappen/ec, no ec-lmtt* under public/lm, no lmmono*.otf. crates/render-pipeline/src/fonts.rs asks for exactly those files (ec_tfm_file → ectt/ecst/ecit/ectc, latin_modern_outline → lmmono*, latin_modern_tfm → ec-lmtt*), so every \texttt/\ttfamily/verbatim run against the bundle fell back to roman: ec_metrics_unavailable (roman ec-lmr* widths, which move the line breaks) plus font_outline_substituted. It was reported, but quietly enough that \texttt geometry had already been measured on the substitution.

What is added — 64 files, no new licence

Both sets come out of upstream packages this tree already vendors, so the licence files already here cover them and none were added.

where files licence already in tree
texmf/fonts/tfm/jknappen/ec/ 44 — {ectt,ecst,ecit,ectc}{0800…3583}.tfm doc/fonts/ec/copyrite.txt
texmf/fonts/tfm/public/lm/ 10 — ec-lm{tt8,tt9,tt10,tt12,tti10,tto10,tcsc10,tcso10,tk10,tko10}.tfm doc/fonts/lm/GUST-FONT-LICENSE.TXT
Fonts/ 10 — lmmono{8,9,10,12}-regular, lmmono10-italic, lmmonoslant10-regular, lmmonocaps10-{regular,oblique}, lmmonolt10-{bold,boldoblique} (669 KB) GUST-FONT-LICENSE.TXT

44 and not 56: t1cmtt.fd declares four shapes (m/n ectt, m/sl ecst, m/it ecit, m/sc ectc) and writes <5><6><7><8>#50800, so 5/6/7 pt load the 8 pt file — 11 distinct sizes — and bx/n/bx/it are ssub*cmtt/m/n/m/it, so there is no bold EC typewriter file to add.

Digests and provenance

The existing tiers were copied from MacTeX 2026 on mac-m1max-a. This host is linux-primary: TeX Live 2025 r78234, no MacTeX. Rather than assert the releases match, it was measured — every file already vendored from these two packages is byte-identical (cmp) between the two distributions: all 70 jknappen/ec TFMs, all 28 public/lm TFMs, all 21 Latin Modern OTFs, all 6 amsfonts/symbols TFMs. The typewriter members were then copied out of the same two directories in the same run, hashed before and after the copy. No CTAN archive is present on this host, so no archive hash is claimed; the sidecars' limitation fields say so.

Both in-repo pins were extended exactly as the roman tiers are pinned — SUPPLEMENTARY-METRICS.json 101 → 155 entries with a tt_provenance block, SUPPLEMENTARY-FACES.json 20 → 30 with a mono_provenance block — so bundle-texmf.py check and make-app.sh verify them and refuse drift.

$ python3 apps/mac/scripts/bundle-texmf.py check Fonts/texmf Fonts
status: verified
entries 194  {(verified, pinned): 9, (verified, supplementary): 155, (verified, supplementary-face): 30}

The guard

crates/render-pipeline/tests/bundled_typewriter.rs (4 tests). It walks every \ttfamily shape through nfss::select/nfss::terminal in all four schemes (OT1/T1 × cm/lm), so an undeclared shape such as bold small-caps typewriter — which LaTeX substitutes before loading any font — is not mistaken for a bundle gap. It then asserts every file the tables can name is on disk and pinned, and renders four \texttt documents asserting zero font_unavailable / required_metrics_unavailable / ec_metrics_unavailable / font_outline_substituted diagnostics. It reads no FLASHTEX_* variable, so it behaves identically with and without the packaging environment.

Gates (measured on this checkout, release builds)

gate before after
real-world corpus font-substitution diagnostics 6 (article-twocolumn 4, input-bibliography 2) 0
real-world corpus total diagnostics 210 204
real-world corpus status/pages per fixture — identical
amsmath oracle corpus 59/59 within 0.5 bp 59/59
crates/render-pipeline cargo test --release, no FLASHTEX_* 170 passed / 0 failed / 1 ignored 174 / 0 / 1
HW1 / HW2 render pages 3 / 3 3 / 3

The corpus baseline was taken against a git archive HEAD apps/mac/Fonts copy of the tree, not against a stale report, and the runner was given the bundled font/TFM directories explicitly (--fonts apps/mac/Fonts alone does not reach the bundled texmf, whose roots are <exe>/../Resources/texmf and <exe>/texmf).

Left out, deliberately

Sans (ecss/ecsi/ecsx/ecso, lmsans*, lmsansdemicond*) and the roman caps/slanted/demi/unslanted designs (eccc/ecui/ecsc/ecrb/ecxc/ecoc, lmromanslant*, lmromancaps*, lmromandemi*, lmromanunsl*) are still absent, so \textsf/\textsc/\textsl on this bundle still substitute and warn. Same shape of problem, out of this lane's scope; recorded in apps/mac/Fonts/README.md as a known gap rather than left implicit.

Resume notes

  • Not run here: the Swift suites. BundledMetricsTests/BundledFacesTests counts were updated to match (155 metric entries, 30 supplementary faces, 33 requestable faces, 10 mono faces) and PreviewFonts.latinModernFaceFiles was extended with a separate latinModernMonoFaceFiles list, but XCTest needs macOS — a Mac lane should run them before merge.
  • Committed oracle data was not regenerated: this host has TeX Live 2025, not the MacTeX 2026 that produced the references.
  • Follow-up worth doing: the same treatment for the sans and roman-variant designs listed above, which would let the completeness guard drop its FamilyKind::Tt restriction.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

GoKubar and others added 2 commits September 13, 2026 13:21
`apps/mac/Fonts` carried no typewriter design at all: no ectt/ecst/ecit/ectc
under jknappen/ec, no ec-lmtt* under public/lm, no lmmono*.otf. The tables in
crates/render-pipeline/src/fonts.rs ask for exactly those files
(`ec_tfm_file` -> ectt/ecst/ecit/ectc, `latin_modern_outline` -> lmmono*,
`latin_modern_tfm` -> ec-lmtt*), so every \texttt/\ttfamily/verbatim run
against the bundle fell back to roman: `ec_metrics_unavailable` (roman ec-lmr*
widths, which move the line breaks) plus `font_outline_substituted`. The
fallback was reported but easy to miss, and typewriter geometry had already
been measured on it.

64 files added, all out of the two upstream packages this tree already
vendors, so no new licence applies and no new licence file is needed:

* jknappen/ec: {ectt,ecst,ecit,ectc}{0800..3583}.tfm -- 44 files, the four
  shapes t1cmtt.fd declares at its 11 distinct sizes. It writes
  <5><6><7><8>#50800, so 5/6/7 pt load the 8 pt file, and bx/n and bx/it are
  ssub*cmtt/m/n and m/it -- there is no bold EC typewriter file to add.
  Covered by doc/fonts/ec/copyrite.txt, already here.
* public/lm: ec-lm{tt8,tt9,tt10,tt12,tti10,tto10,tcsc10,tcso10,tk10,tko10}.tfm
  -- 10 files, the metrics t1lmtt.fd loads. GUST Font License, already here.
* Fonts/: lmmono{8,9,10,12}-regular, lmmono10-italic, lmmonoslant10-regular,
  lmmonocaps10-{regular,oblique}, lmmonolt10-{bold,boldoblique} -- 10
  outlines, 669 KB, every file latin_modern_outline returns for
  FamilyKind::Tt. Same Latin Modern release as the 21 lmroman* faces here.

Provenance: the earlier tiers were copied from MacTeX 2026 on mac-m1max-a.
This host is linux-primary, which has TeX Live 2025 r78234 and no MacTeX, so
release identity was measured rather than asserted -- every file already
vendored from these two packages is byte-identical (cmp) between the two
distributions: all 70 jknappen/ec TFMs, all 28 public/lm TFMs, all 21 Latin
Modern OTFs, all 6 amsfonts/symbols TFMs. The typewriter members were copied
from the same two directories in the same run and hashed before and after the
copy. No CTAN archive is present here, so no archive hash is claimed; the
sidecars' `limitation` fields say so.

Both in-repo pins were extended the same way the roman tiers are pinned --
SUPPLEMENTARY-METRICS.json 101 -> 155 entries with a `tt_provenance` block,
SUPPLEMENTARY-FACES.json 20 -> 30 with a `mono_provenance` block -- so
`bundle-texmf.py check` and `make-app.sh` verify them and refuse drift.
`bundle-texmf.py check Fonts/texmf Fonts`: 194 entries, all verified, none
unpinned.

crates/render-pipeline/tests/bundled_typewriter.rs is the guard. It walks
every \ttfamily shape through nfss::select/nfss::terminal in all four schemes
(OT1/T1 x cm/lm) -- so an undeclared shape such as bold small-caps typewriter,
which LaTeX substitutes before loading a font, is not mistaken for a bundle
gap -- asserts every file the tables can then name is on disk and pinned, and
renders four \texttt documents asserting zero font_unavailable /
required_metrics_unavailable / ec_metrics_unavailable /
font_outline_substituted diagnostics. It reads no FLASHTEX_* variable, so it
behaves the same with and without the packaging environment.

Measured on this checkout (flashtex-render + flashtex-compiler, release):

* real-world corpus (10 fixtures, tools/real-world-corpus/run.py, bundled
  font dirs passed explicitly): font-substitution diagnostics 6 -> 0
  (article-twocolumn 4 -> 0, input-bibliography 2 -> 0); total diagnostics
  210 -> 204; every fixture's status and page count unchanged.
* amsmath oracle corpus: 59/59 within 0.5 bp, before and after.
* crates/render-pipeline `cargo test --release` with no FLASHTEX_* exports:
  174 passed, 0 failed, 1 ignored (was 170/0/1; the four new ones are this
  file).

Still not vendored, and still silently substituting: sans
(ecss/ecsi/ecsx/ecso, lmsans*, lmsansdemicond*) and the roman
caps/slanted/demi/unslanted designs (eccc/ecui/ecsc/ecrb/ecxc/ecoc,
lmromanslant*, lmromancaps*, lmromandemi*, lmromanunsl*). Same shape of
problem, not fixed here; recorded in apps/mac/Fonts/README.md.

The Swift counts in BundledMetricsTests/BundledFacesTests were updated to
match (155 metric entries, 30 supplementary faces, 33 requestable faces) but
could not be run here -- XCTest needs macOS.

Implementation-Agent: engine-engineer (linux-primary, NixOS PC)
Commit-Executor: engine-engineer via git (Cursor usage limit fallback)
Co-authored-by: GoKubar <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
Adding the files is only half of it: they also have to be reachable by the
reader that demands them. This adds the missing case to the guard, and
records what was actually measured, because the claim going round -- that
FLASHTEX_TFM_DIRS does not feed the rooted required-metrics reader -- is not
what the code does.

`FontSet::texmf_roots` (fonts.rs) derives a texmf root from any
FLASHTEX_TFM_DIRS entry by stripping the `fonts/tfm/public/lm` suffix, and
`required_metrics` tries those roots first and then every TFM directory as a
flat root. So the environment route does reach the rooted reader -- but only
when the entry is spelled `<root>/fonts/tfm/public/lm` (or is a flat
directory holding the four required TFMs next to GUST-FONT-LICENSE.TXT).
Pointing the variable at `apps/mac/Fonts` itself yields no derivable root and
no flat root, and everything falls back. That spelling, not a missing code
path, is the whole 0/59-vs-59/59 difference on the amsmath corpus.

Measured here with this checkout's flashtex-render, one \texttt + math
document, counting font_unavailable / required_metrics_unavailable /
ec_metrics_unavailable / font_outline_substituted / tfm_missing /
math_font_unavailable:

  PASS  FLASHTEX_TFM_DIRS = the three rooted metric directories
  FAIL  FLASHTEX_TFM_DIRS = apps/mac/Fonts        (5 diagnostics; the trap)
  PASS  <exe>/../Resources/{texmf,Fonts}, no FLASHTEX_*   (app bundle)
  PASS  <exe>/texmf + <exe>/Fonts, no FLASHTEX_*          (tarball)

And on the rooted route specifically, before vs after this branch's font
files, `<exe>/texmf + <exe>/Fonts` with no FLASHTEX_* at all:

  FAIL  HEAD:        2 diagnostics (lmmono12-regular.otf not found;
                     ectt1200.tfm not found, ec-lmr12.tfm used)
  PASS  this branch: 0 diagnostics

So the packaging layout was already correct for the required 12 pt metrics on
both rooted paths; what it could not do was answer a \texttt request, because
no typewriter file existed to answer it with. No packaging change is needed.

`the_bundled_typewriter_files_are_reachable_by_every_discovery_route` stages
both bundle layouts in a temp directory, builds the FontSet through
`FontSet::from_discovery` with `exe_dir` pointed at the staged binary
directory (no FLASHTEX_* read), renders the four probe documents through each
and asserts zero substitution diagnostics -- and asserts that the
apps/mac/Fonts-as-TFM-dir spelling still FAILS `required_metrics`, so the
trap cannot quietly start passing.

crates/render-pipeline `cargo test --release --test bundled_typewriter`:
5 passed, 0 failed.

Implementation-Agent: engine-engineer (linux-primary, NixOS PC)
Commit-Executor: engine-engineer via git (Cursor usage limit fallback)
Co-authored-by: GoKubar <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@GoKubar

GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up: the rooted discovery path, and a control-compared test matrix

Two points were raised against this PR. Both are now measured rather than argued.

1. "FLASHTEX_TFM_DIRS does not feed the rooted required-metrics reader." That is not what the code does. FontSet::texmf_roots (crates/render-pipeline/src/fonts.rs) derives a texmf root from any FLASHTEX_TFM_DIRS entry by stripping the fonts/tfm/public/lm suffix, and required_metrics tries those roots first and then every TFM directory as a flat root. The environment route does reach the rooted reader — but only when the entry is spelled <root>/fonts/tfm/public/lm (or is a flat directory holding the four required TFMs next to GUST-FONT-LICENSE.TXT). Pointing the variable at apps/mac/Fonts itself yields no derivable root and no flat root, and everything falls back. That spelling, not a missing code path, is the whole 0/59-vs-59/59 difference on the amsmath corpus.

Measured with this checkout's flashtex-render, one \texttt + math document, counting font_unavailable / required_metrics_unavailable / ec_metrics_unavailable / font_outline_substituted / tfm_missing / math_font_unavailable:

route result
FLASHTEX_TFM_DIRS = the three rooted metric directories PASS (0)
FLASHTEX_TFM_DIRS = apps/mac/Fonts FAIL (5) — the trap
<exe>/../Resources/{texmf,Fonts}, no FLASHTEX_* (app bundle) PASS (0)
<exe>/texmf + <exe>/Fonts, no FLASHTEX_* (tarball) PASS (0)

And on the rooted route specifically, before vs after this branch's font files (<exe>/texmf + <exe>/Fonts, no FLASHTEX_* at all):

result
HEAD FAIL — 2 diagnostics: lmmono12-regular.otf not found; ectt1200.tfm not found, ec-lmr12.tfm used
this branch PASS — 0

So the packaging layout was already correct for the required 12 pt metrics on both rooted paths. What it could not do was answer a \texttt request, because no typewriter file existed to answer it with. No packaging change is needed. the_bundled_typewriter_files_are_reachable_by_every_discovery_route (commit c5cfd9b5) stages both bundle layouts in a temp directory, builds the FontSet through FontSet::from_discovery with exe_dir pointed at the staged binary directory, renders the four probe documents through each and asserts zero substitution diagnostics — and asserts the apps/mac/Fonts-as-TFM-dir spelling still fails required_metrics, so the trap cannot quietly start passing.

2. "cargo test guarded by lm_available() masks failures; run with fonts and compare against a control." Agreed on the method; here is the full matrix. cargo test --release --no-fail-fast on crates/render-pipeline, control = a git archive checkout of the shared base 89e49fed:

checkout no FLASHTEX_* with fonts configured
control 89e49fed 170 / 0 / 1 162 / 8 / 1
this branch (#183) 175 / 0 / 1 167 / 8 / 1
#187 (literal/verbatim) 172 / 0 / 1 164 / 8 / 1

The failing sets are byte-identical across all three (diff of the sorted names), so those 8 are pre-existing and unaffected by either branch.

They are also not product bugs. They are tests that deliberately build a partial-font control and are contaminated by a global font environment, because FontSet::new reads FLASHTEX_TFM_DIRS itself:

  • missing_required_metrics_are_a_blocking_diagnostic_not_a_silent_fallback — assertion failed: fonts.required_metrics().is_err(): it points a FontSet at a directory of OTFs with no TFM sibling, and the environment hands the real metrics back.
  • mathbb_paints_from_new_computer_modern_when_bundled — ℤ without NewCM: left "NewCMMath-Regular", right "LatinModernMath-Regular": the control that should not see NewCM gets it from FLASHTEX_FONT_DIRS.

Neither font mode is "the" number on its own, and the durable fix is for those 8 to construct their FontSet env-free with FontSet::with_dirs — which is what the five tests added here already do, and why they pass identically in both modes.

@GoKubar
GoKubar marked this pull request as ready for review September 13, 2026 18:47
@GoKubar
GoKubar merged commit f447115 into main Sep 13, 2026
14 of 20 checks passed
GoKubar added a commit that referenced this pull request Sep 13, 2026
Fixes the three pre-existing fidelity failures (font_family_fixtures, footnotes_against_pdflatex, page_frame_against_pdflatex) by bundling the tier the renderer already maps to. Provenance by byte-comparison against pinned files (#183 method). Commander-approved for the v0.1.2 release sequence.
@GoKubar
GoKubar deleted the agent/kabir-claude/bundle-typewriter-fonts 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