Skip to content

render-pipeline: NFSS font families, shapes and math alphabets (sans, typewriter, small caps, slanted, \mathsf/\mathfrak) - #134

Merged
jay3332 merged 4 commits into
mainfrom
agent/kabir-claude/font-families
Sep 13, 2026
Merged

jay3332 merged 4 commits into
mainfrom
agent/kabir-claude/font-families

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Based on main 85ec30c7 (merged in; no stacking). No vendor/ edits, no compiler change needed to build: the adapter already re-reads font commands from the source bytes.

What

Text fonts are now selected the way LaTeX does it: \fontfamily/\fontseries/\fontshape + \selectfont.

New src/nfss.rs transcribes, with line citations:

  • the shape change rules (latex.ltx 12361-12399) and series change rules (12056-12076);
  • \merge@font@shape@ and \merge@font@series@;
  • \wrong@fontshape substitution (shape n, then series m, then family);
  • the .fd declarations, including sub*/ssub*: ot1cmr/ot1cmss/ot1cmtt, t1cmr/t1cmss/t1cmtt, t1lmr/t1lmss/t1lmtt.

It emits pdflatex's warnings verbatim, for example Font shape `OT1/cmr/bx/sc' undefined, using `OT1/cmr/bx/n' instead.

Adapter. Every text font command and declaration is applied outermost first, so order matters exactly as in LaTeX:

  • text commands: \textrm/sf/tt, \textmd/bf, \textit/sl/sc/up, \textnormal, \emph;
  • declarations: \rmfamily…\normalfont, \em;
  • 2.09 forms: \bf \it \sl \sc \rm \sf \tt.

\em and the \maybe@ic italic correction follow the slant of the font actually loaded. For example, \textsc{\emph{x}} gives OT1 m/it but T1/lmodern m/scsl.

Faces.

  • Family::ComputerModern (T1) uses EC metrics: ecss/ecsi/ecsx/ecso, eccc/ecxc/ecsc/ecbl/ecoc/ecrb, ectt/ecst/ecit/ectc. Sans and typewriter follow the <5-8>→0800 rule.
  • Family::LatinModern uses ec-lm* metrics.
  • Outlines come from the Latin Modern designs with their .fd optical sizes: lmsans, lmromancaps, lmromanslant, lmromandemi, lmmono*.
  • If a design file is missing, the shape keeps its own metrics and draws the roman design of the same weight and slant, with a font_outline_substituted warning (no Times fallback). Latin Modern has no bold small caps, so ecxc draws lmromancaps10 and says so.
  • Typewriter faces set \hyphenchar=-1.
  • Times documents: sf → Helvetica, tt → Courier.

microtype resolves the loaded NFSS font: family cmss/lmtt…, series and shape after substitution, and the document's encoding. HW1/HW2 still resolve exactly T1/cmr as before.

Verification

  • Oracle: 46 fixtures (fixtures/font-families, make_fixtures.py + oracle.py; pdflatex is test-only, cargo never runs TeX).
    • Coverage: every family × series × shape combination in OT1, T1 and T1+lmodern, \emph nesting, declarations, 2.09 forms, sizes, and bold/sans/tt substitutions.
    • Comparison: segment text, font design (CM/cm-super/LM Type 1 name ↔ LM OpenType design), x and baseline within 0.5 bp, and every pdflatex font warning.
    • 45/46 pass. Worst |dx| is 0.40 bp (emph nesting); every upright and slanted shape fixture is within 0.075 bp, and the OT1 italics within 0.30 bp.
    • 41-t1-sans-latex (\textsf{\LaTeX}) is PENDING: main has no logo boxes yet (render-pipeline: set \TeX/\LaTeX logos, \rule and text kerns (stacked; needs vendor re-pin) #129). The test fails if it starts matching, so the entry gets removed.
  • Gates.
    • cargo test --release: all green, including 6 new nfss unit tests and a fonts mapping test.
    • HW1/HW2 v2 display lists are byte-identical to main 85ec30c7 (sha256 d2cdd486…, 0e5d2181…).
    • Real-world corpus: no page, error or warning count changed. article-twocolumn and input-bibliography now draw \texttt in LM Mono; the other 7 are byte-identical.

Mac bundle: files these shapes need (none are in apps/mac/Fonts today)

Without them the app draws roman outlines with the requested metrics where the TFM is found, and warns.

  • OTF (fonts/opentype/public/lm, 33):
    • lmsans{8,9,10,12,17}-{regular,oblique}, lmsans10-{bold,boldoblique}
    • lmromancaps10-{regular,oblique}, lmromanslant{8,9,10,12,17}-regular, lmromanslant10-bold
    • lmromandemi10-{regular,oblique}, lmromanunsl10-regular
    • lmmono{8,9,10,12}-regular, lmmono10-italic, lmmonoslant10-regular, lmmonocaps10-{regular,oblique}, lmmonolt10-{bold,boldoblique}
  • LM TFM (fonts/tfm/public/lm, 33):
    • ec-lmss{8,9,10,12,17}, ec-lmsso{8,9,10,12,17}, ec-lmssbx10, ec-lmssbo10
    • ec-lmcsc10, ec-lmcsco10, ec-lmro{8,9,10,12,17}, ec-lmbxo10, ec-lmb10, ec-lmbo10, ec-lmu10
    • ec-lmtt{8,9,10,12}, ec-lmtti10, ec-lmtto10, ec-lmtcsc10, ec-lmtcso10, ec-lmtk10, ec-lmtko10
  • EC TFM (fonts/tfm/jknappen/ec, 186):
    • {eccc,ecxc,ecbl,ecsc,ecoc,ecrb,ecui} × 14 sizes (0500…3583)
    • {ecss,ecsi,ecsx,ecso,ectt,ecst,ecit,ectc} × 11 sizes (0800…3583)

Math alphabets (second commit)

fontmath.ltx sets \mathbf, \mathsf, \mathit and \mathtt in the text fonts OT1 cmr/bx/n, cmss/m/n, cmr/m/it and cmtt/m/n (lmodern: lmr/lmss/lmtt). amsfonts.sty sets \mathfrak in U/euf (ueuf.fd: eufm5 below 6 pt, eufm7 below 8 pt, else eufm10).

New src/mathalpha.rs maps the compiler's Unicode mathematical alphanumerics (#136) back to the alphabet and letter.

Runs of two or more characters of a text alphabet go through the math text sink in that NFSS shape:

  • Latin Modern metrics of the design (ec-lm*, equal to rm-lm* for letters and digits) at the .fd optical size.
  • TFM kerns and ligatures, with no italic correction between characters.
  • The last character's italic correction as δ (TeX §752).
  • \mathbf{...} (already a compiler nucleus) now uses the bold roman font, so its "set in the regular roman face" limitation is gone.

One character is a math character, as in TeX, where §1186 unpacks the one-Ord group:

  • TexMathMetrics::with_alphabets loads the alphabets the sources name.
  • It supplies that character's TFM box, with the char rule for scripts, drawn from the Latin Modern text face.

Fraktur gets eufm TFM boxes and Latin Modern Math's (Euler) fraktur outlines. fonts/tfm/public/amsfonts/euler is added to TFM discovery.

Oracle fixtures 47-50 (T1, OT1, lmodern):

Bundle additions for math alphabets: eufm5/7/10.tfm (fonts/tfm/public/amsfonts/euler). The sans, typewriter, bold and italic faces and TFMs are already in the list above.

Notes and follow-ups

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

GoKubar and others added 3 commits September 13, 2026 07:24
Implementation-Agent: Claude Opus 5 (subagent kabir-claude font families, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
…small caps, slanted)

Text fonts are selected the way LaTeX's \fontfamily/\fontseries/\fontshape
+ \selectfont do (new src/nfss.rs): the shape/series change rules of
latex.ltx, \wrong@fontshape substitution and the ot1cm*/t1cm*/t1lm*.fd
declarations (sub*/ssub*), with pdflatex's font warnings. The adapter
applies every text font command and declaration (\textsf, \scshape,
\ttfamily, \bf, ...) outermost first; \em follows the loaded font's slant.
Faces: EC metrics (ecss, eccc, ectt, ...) or ec-lm* metrics with the Latin
Modern designs (lmsans, lmromancaps, lmmono, ...); a missing design keeps
its metrics and draws the roman one with a warning. microtype resolves the
loaded NFSS font (family, series, shape, encoding).

Oracle: 46 fixtures vs MacTeX 2026 pdflatex (OT1, T1, T1+lmodern), 45
within 0.5 bp with the same designs and warnings; 41 pending the \LaTeX
logo (#129). HW1/HW2 display lists byte-identical to main 85ec30c.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude font families, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
…d \mathfrak

The compiler's Unicode mathematical alphanumerics (companion PR #136) and
\mathbf are set in the fonts fontmath.ltx/amsfonts.sty use: runs of a text
alphabet through the math text sink in that NFSS shape (TFM kerns and
ligatures, last italic correction as delta), a single character as a math
character from its TFM (TeX 1186), fraktur from eufm5/7/10 boxes with Latin
Modern Math's Euler outlines. eufm TFM directory added to discovery.

Oracle fixtures 47-50: \mathbf passes on main's vendor (0.15 bp); the
alphabet fixtures are PENDING on the #136 re-pin and match pdflatex within
0.39 bp in a scratch build with #136 vendored. HW1/HW2 byte-identical.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude font families, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
@GoKubar GoKubar changed the title render-pipeline: NFSS font families, series and shapes (sans, typewriter, small caps, slanted) render-pipeline: NFSS font families, shapes and math alphabets (sans, typewriter, small caps, slanted, \mathsf/\mathfrak) Sep 13, 2026
@jay3332
jay3332 merged commit e0ca0d0 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-13k (Commander).

@GoKubar
GoKubar deleted the agent/kabir-claude/font-families 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