Skip to content

compiler: em/ex for slanted and small-caps fonts from real TFM fontdimens (stacked on #587) - #618

Merged
GoKubar merged 10 commits into
mainfrom
agent/daniel-parent/fontdimens-sl-sc
Sep 15, 2026
Merged

GoKubar merged 10 commits into
mainfrom
agent/daniel-parent/fontdimens-sl-sc

Conversation

@d-q222

@d-q222 d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

What

Stacked on #587. em/ex for slanted (\slshape, \textsl) and small-caps (\scshape, \textsc) fonts now come from the real TFM fontdimens, not from the italic values. This works on both the parser path and the expansion register path.

Class sl em / ex sc em / ex \bfseries\scshape em / ex
10pt 10.00002 / 4.30554pt 11.05545 / 4.30554pt 11.49994 / 4.44444pt
11pt 10.95003 / 4.71457pt 12.10571 / 4.71457pt 12.59242 / 4.86665pt
12pt 11.74988 / 5.16667pt 13.26654 / 5.16666pt 13.5 / 5.33331pt

bx/sc falls back to bx/n, matching pdflatex's substitution warning. The values come from pdflatex \showthe, via #587's generator (gen_text_fontdimens.py). Rerunning the generator produces byte-identical output.

Why

It closes items (a) and (b) of #587's Not done. Item (c), \normalfont resetting the size, is assigned separately.

Overlap check

Test results

  • compiler: lib 339 passed, all integration targets pass.
  • tex-expansion: 55 + 3 + 2 passed.

Not done

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

What changed:
- Preserve font-relative metrics in expansion checkpoints and shifted incremental checkpoints.

What was run:
- test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
- test result: ok. 55 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.01s
- test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 2.25s
- test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s
- test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Next step:
- Integrate compiler font-relative dimension handling.

Implementation-Agent: codex gpt-5.6-luna (max)
Commit-Executor: codex (this session)
Lane-Owner: daniel-parent (mac-m5pro-dq222)
What changed:
- Resolve em/ex dimensions from the active compiler class, size declaration, and known Core14 family metrics.
- Preserve source interword glue around hspace and accept parser-owned global length prefixes, including table length names.
- Add pdflatex-measured regression coverage for dimensions, register values, grouping, and invalid global setlength.

What was run:
- test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s
- test result: ok. 18 passed; 0 failed; 0 ignored; 0 measured; 321 filtered out; finished in 0.01s
- test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 7 filtered out; finished in 0.00s
- test result: ok. 339 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.48s

Next step:
- Integrate this branch into the parent branch.

Implementation-Agent: codex gpt-5.6-luna (max)
Commit-Executor: codex (this session)
Lane-Owner: daniel-parent (mac-m5pro-dq222)
…\setlength is valid

Addresses the independent review on #587.

What changed:
- em/ex are the selected text font's \fontdimen6/\fontdimen5, not the
  class point size. src/text_fontdimens.rs (generated by
  scripts/gen_text_fontdimens.py from pdflatex) records them for
  OT1/T1 x CM/lmodern x rm/sf/tt x m/bx x n/it x the 12 LaTeX sizes.
  cmr12's quad is 11.74988pt, so 12pt 3em = 35.24963pt.
- The parser path resolves \small/\large/\bfseries/\sffamily/\ttfamily/
  italics/fontenc/lmodern through it, scaling with TeX's §455 arithmetic
  (0.65em in ecrm1095 = 7.07704pt).
- tex-expansion tracks host font switches (\small, \bfseries, \textbf{..},
  \emph, ...) as a grouped font selector and asks FontMetrics::quad_sp_in.
  Checkpoints keep the metrics provider, so restored engines match.
- \global\setlength / \global\addtolength are passed to the parser and
  applied globally (pdflatex accepts them; \setlength is a macro).
- \fboxsep=/\fboxrule= assignments work in the body with \global; a body
  \parskip= gets the same "not implemented" warning as \setlength.
- Table lengths are documented as stateless; their test no longer claims
  to check scoping.

What was run:
- cargo test --manifest-path crates/compiler/Cargo.toml --no-fail-fast:
  58 targets, all "test result: ok"; lib "ok. 339 passed; 0 failed";
  em_global "ok. 11 passed; 0 failed"; preamble_lengths "ok. 13 passed; 0 failed";
  expansion_incremental "ok. 2 passed; 0 failed"
- cargo test --manifest-path crates/tex-expansion/Cargo.toml:
  "ok. 55 passed", "ok. 3 passed", "ok. 2 passed"

Next step: independent re-review, then vendor re-pin after merge.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
What changed:
- Generate deterministic em/ex rows for upright, italic, slanted, and small-caps NFSS shapes across the existing setups.
- Track slanted and small-caps styles on parser and expansion register paths, including bx/sc fallback coverage.
- Pin pdflatex 10/11/12pt sl/sc and bfseries/sc values.

What was run:
- python3 crates/compiler/scripts/gen_text_fontdimens.py --texbin /Library/TeX/texbin
- CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-sl-sc CARGO_BUILD_JOBS=4 cargo test --manifest-path crates/tex-expansion/Cargo.toml
- CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-sl-sc CARGO_BUILD_JOBS=4 cargo test --manifest-path crates/compiler/Cargo.toml

Next step:
- Integrate this commit into the parent branch.

Implementation-Agent: codex gpt-5.6-luna (max)
Commit-Executor: codex (this session)
Lane-Owner: daniel-parent (mac-m5pro-dq222)
@d-q222

d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

daniel-parent independent review (subagent)
Verdict: APPROVE

  1. Spot-checked 3 table cells directly against pdflatex 3.141592653-2.6-1.40.29 (TeX Live 2026, the same binary/version gen_text_fontdimens.py recorded) using standalone \documentclass[Npt]{article} probes reading \the\fontdimen6\font/\the\fontdimen5\font:
    • 10pt \slshape em/ex: measured 10.00002pt / 4.30554pt vs. claimed 10.00002 / 4.30554pt — exact match.
    • 11pt \scshape ex: measured 4.71457pt vs. claimed 4.71457pt — exact match (em also matched: 12.10571pt).
    • 12pt \bfseries\scshape em: measured 13.5pt vs. claimed 13.5 — exact match (ex also matched: 5.33331pt).
  2. bx/sc fallback confirmed against pdflatex directly: compiling \bfseries\scshape on 10pt emits LaTeX Font Warning: Font shape OT1/cmr/bx/sc' undefined (Font) using OT1/cmr/bx/n' instead, and \fontname\font reports cmbx10. The PR's generated table row for bold+small_caps (text_fontdimens.rs, lm=False t1=False Roman bold=True shape=small_caps) lists the same font names (cmbx10, cmbx12, ...) and is byte-identical to the bold+upright row — the fallback is correctly baked into the measured data itself (pdflatex substitutes before the generator records \fontdimen), not a separate ad hoc rule that could drift from real behavior.
  3. Confirmed gen_text_fontdimens.py reads \fontdimen6 for em (quad) and \fontdimen5 for ex (x-height) — the correct TeXbook ch.10 convention — across all NFSS setups/families/series/shapes/sizes it enumerates.
  4. Confirmed both paths independently locate and use the same underlying table: the parser path (parser.rs::font_setup() → FontSetup::em_ex_sp, wired into parse_dimen_pt_current for \hspace, \vspace, \setlength, TeX-style assignments) and the expansion-register path (tex-expansion/src/expand.rs::scale_unit → EngineFontMetrics::quad_sp_in/x_height_sp_in, fed by font_units::font_switches() registered via Engine::declare_font_switch in expansion.rs::configure_with_fonts). Both delegate to FontSetup::em_ex_sp and the same FONTDIMENS table, so there's no risk of the two paths diverging on the same input; apply_style in parser.rs and the font_switches() bitmask in font_units.rs both correctly encode slanted/small-caps precedence (small_caps > slanted > italic > upright) consistently.
  5. Ran the PR's own listed tests narrowly in an isolated target dir: compiler --lib 339 passed (claimed 339); tex-expansion 55 + 3 + 2 passed (claimed 55 + 3 + 2); em_global 11 passed, preamble_lengths 13 passed, amsthm 19 passed — all green, no discrepancies from the PR's reported counts.

No issues found. The expansion cache also correctly invalidates on DocumentFonts change (class size/fontenc/lmodern), which matters for the incremental path staying consistent with these new per-shape metrics.

Conflicts: crates/compiler/src/parser.rs (both sides added TABLE_LENGTHS;
kept main's const/doc, updated main's dispatch arm to the branch's
three-argument length_assignment with \global support) and
crates/tex-expansion/src/registers.rs (kept branch's xn_over_d and
scale_internal_dimen, dropped the branch's duplicate round_decimals in
favour of main's public one, kept main's tests). Regenerated
supported-latex artifacts; bundled copy in sync.

Implementation-Agent: fable-rebase-d
Commit-Executor: fable-rebase-d (direct; Cursor usage limit)
…olved) into agent/daniel-parent/fontdimens-sl-sc

Clean merge of the parent branch's main-merge; regenerated
supported-latex artifacts (no drift), bundled copy in sync.

Implementation-Agent: fable-rebase-d
Commit-Executor: fable-rebase-d (direct; Cursor usage limit)
/#568)

Conflicts:
- crates/compiler/src/parser.rs: both sides appended P fields; kept both.
- crates/compiler/src/expansion.rs: #610 replaced the halted/re-expand
  flag with recovered/resume-unexpanded and threads limits through
  build_cache; kept that structure and carried this branch's
  DocumentFonts cache key and configure_with_fonts init.
- crates/tex-expansion/src/expand.rs, incremental.rs: kept both sides'
  new State/Checkpoint fields (font_switches/pending_font_switch/metrics
  and group/conditional_limit_reported/last_origin/peak_memory); dimen
  scanning combines main's clamped_number with this branch's
  scale_unit/scale_internal_dimen em/ex handling.
Regenerated supported-latex artifacts; bundled copy in sync.

Implementation-Agent: fable-rebase-d
Commit-Executor: fable-rebase-d (direct; Cursor usage limit)
 glue)

Conflict: crates/compiler/src/parser.rs \vspace — #606 parses rubber
glue (parse_glue_pt_at), this branch parses em/ex against the active
font. Combined: parse_glue_pt_current parses each glue component with
parse_dimen_pt_current. Updated #606's vspace glue test to the branch's
pdflatex-verified em semantics (1em = cmr10 quad 10.00002pt, not
BODY_SIZE_PT) and widened Block::VSpace patterns in this branch's tests
for the new stretch/shrink fields.

Implementation-Agent: fable-rebase-d
Commit-Executor: fable-rebase-d (direct; Cursor usage limit)
Merged the final 587 branch tip first, then main; main's squash of #587
is byte-identical to that tip for the four add/add files
(font_units.rs, text_fontdimens.rs, em_global.rs,
gen_text_fontdimens.py), so the branch side — 587 final plus this
branch's slanted/small-caps fontdimens — is the resolution. All other
files auto-resolved. Regenerated supported-latex artifacts; bundled
copy in sync.

Implementation-Agent: fable-rebase-d
Commit-Executor: fable-rebase-d (direct; Cursor usage limit)
@GoKubar
GoKubar merged commit 9dc9d1c into main Sep 15, 2026
10 of 21 checks passed
GoKubar added a commit that referenced this pull request Sep 15, 2026
/#635 grew the inventory

docs/user/compiler.md (generated) conflicted again; took main's copy and
regenerated via render_supported_latex.sh so \underbar and main's
additions both appear, sync --check clean.

Implementation-Agent: fable-rebase-a
Commit-Executor: fable-rebase-a (direct; Cursor usage limit)
@GoKubar
GoKubar deleted the agent/daniel-parent/fontdimens-sl-sc branch September 16, 2026 04:16
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