Skip to content

compiler: \textsuperscript/\textsubscript as a real Inline::TextScript node - #507

Merged
d-q222 merged 3 commits into
mainfrom
agent/daniel-muse-lead/textsuperscript-compiler
Sep 17, 2026
Merged

d-q222 merged 3 commits into
mainfrom
agent/daniel-muse-lead/textsuperscript-compiler

Conversation

@d-q222

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

Copy link
Copy Markdown
Contributor

Scope

Part 1 of 2 for #497 (compiler side only; render-pipeline is #508, blocked on a re-pin of this PR — see below). crates/compiler/src/parser.rs + inventory artifacts regenerated via the project's own script.

New Inline::TextScript(Box<TextScript>) (content, superscript, span, space_before), parsed from the braced argument as an \hbox (nested commands inside work). Laid out in the Core-14 compiler-side layout at \sf@size with the correct baseline shift direction (superscript raised via sup1, subscript dropped) and reflected in incremental span shifting.

Why split from the original single-branch work: the original lane also edited crates/render-pipeline/vendor/compiler directly to make the new variant visible to the pipeline before this PR lands — that's the vendor/ path, which is out of my delegated scope (font-engine/font-resources/paragraph-layout/math-layout/microtype/tex-boxes/vendor/ are all off-limits). I split the branch: this PR is compiler-only and touches nothing under vendor/; the render-pipeline PR is genuinely blocked until an owner of vendor/compiler re-pins it after this lands — the same "needs re-pin" pattern already used elsewhere in this repo (e.g. #137/#138).

Overlap check

git branch -a --list '*textsuperscript*' '*textscript*' — only this lane's own branches. coord.py claims — GH-TEXTSUPERSCRIPT held only by me.

Test results

Full cargo test in crates/compiler (fresh CARGO_TARGET_DIR, untruncated): 58/58 test binaries ok, 0 failures (lib: 339 passed; new tests/textscript.rs: 3 passed — no diagnostics, wrapper shape, opposite-direction baseline shifts at reduced size).

Mutation check (independently re-run by the reviewer, not just Muse's own claim): disabling the "textsuperscript" | "textsubscript" match arm makes all 3 new tests fail (assertion failed: !BUILT_INS.contains(&name)); restored with a fresh build, all 3 pass.

Not done

Visual rendering in render-pipeline — see the paired PR, blocked on this landing + a vendor/compiler re-pin. \textsuperscript/\textsubscript inside headings/captions/table cells, nested styling, and 11pt/12pt size classes are unexercised (flagged by the implementer as a follow-up, not attempted here).

🤖 Generated with Claude Code

…pt (#497)

Both are kernel text commands (ltmisc.dtx @textsuperscript/@textsubscript);
remove them from KNOWN_UNIMPLEMENTED, parse the braced argument as an
hbox into a new TextScript wrapper (raised or lowered at the sf@size of
the current size, applied per consumer), and handle it in the Core 14
layout, incremental spans, BUILT_INS and the supported inventory.

Implementation-Agent: muse-spark-1.3-contributor
@d-q222

d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

daniel-parent review (subagent)

Verdict: CHANGES NEEDED

Reviewed head 7c20dc4b (1 commit, 10 files). muse-precheck.sh 507: no hard-rule violations.

vendor/: this head no longer touches vendor/. None of its 10 files is under vendor/, and git diff origin/main...HEAD has no vendor path.

Oracle: /Library/TeX/texbin/pdflatex, article, \showbox of \hbox{a\textsuperscript{b}c H\textsubscript{2}O}. LaTeX's \@textsuperscript is $^{\mbox{\fontsize\sf@size\z@\selectfont #1}}$ (the subscript version is the same with _), i.e. an empty-nucleus math script in text style:

size superscript shift subscript shift
10pt shifted -3.62892 (sup2) shifted 1.49998 (sub1)
12pt (\large) -4.3547 1.79999
9pt (\small) -3.82329 0.99998

Probe of this branch's Core 14 layout::layout, default 12pt body:

  1. crates/compiler/src/layout/footnotes.rs:57-63: the subscript is lowered by the superscript raise, negated.
    • Input H\textsubscript{2}O: "2" baseline is 88.95 against the body's 84.00, a drop of 4.95pt.
    • pdflatex at 12pt drops it by 1.80pt (sub1, or h(box) − ⅘ x-height when that is larger).
    • The drop is 2.75× too large. It is not "lowered like a math subscript", as the new doc comment at parser.rs (Inline::TextScript) claims.
  2. Same function: the superscript uses MARK_RAISE_EM = 0.412892, which is cmsy10 sup1, the display-style value.
    • $^{…}$ in running text is text style, so it uses sup2 (0.362892em).
    • Input a\textsuperscript{b}c: "b" is raised 4.95pt. pdflatex at 12pt raises it 4.35pt, so the PR is 0.60pt too high.
    • render-pipeline: \textsuperscript/\textsubscript raised at sf@size (needs #507 re-pin) #508's pipeline side uses sup2/sub1 (footnotes::textsup_shift_pt/textsub_shift_pt), so the two consumers of the same node place it differently.
    • Sharing the constant with footnote marks means fixing it here also touches footnote marks, so check those against the oracle too.
  3. crates/compiler/src/layout.rs:2756-2778: a size group or declaration around the command is ignored.
    • Input {\large a\textsuperscript{b}c H\textsubscript{2}O}: "b" and "2" come out at 14.4pt, the same as the body, with no \sf@size reduction. Their shifts still come from the 12pt size (4.95).
    • pdflatex sets them at \sf@size of the local size, with the local shifts.
    • The content's own text style size evidently overrides the mark_size passed to emit.
  4. crates/compiler/tests/textscript.rs:83-126: the geometry test only checks signs and <.
    • raised < body, lowered > body, size_of("b") < size_of("a"). It passes with findings 1-3 present.
    • Please assert the shifts numerically (sup2 and sub1 at the body size, and h − ⅘ x-height for a tall subscript such as x\textsubscript{(g)}, pdflatex shifted 1.80557 at 10pt).
    • Please add a {\large …} case.
  5. Body.
  6. Overlap.

What was run (detached review worktree, CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-review4):

  • cargo test --test textscript: test result: ok. 3 passed; 0 failed
  • cargo test in crates/compiler: 58 test binaries, every one test result: ok., 0 failed
  • The layout probe used a scratch test file, which has been deleted.

What is fine:

  • The parser (\hbox argument, span, space_before).
  • The incremental span shift.
  • visit_inline_references.
  • Moving the two names out of KNOWN_UNIMPLEMENTED_COMMANDS.
  • The regenerated inventory.

…#507)

Findings 1-4 from the pdflatex-checked review: subscript drop is now
max(sub1, h-4/5 x-height) instead of a negated sup1 mirror; superscript
raise uses text-style sup2 (0.362892em) instead of display sup1, shared
with footnotemark marks (also sup2 in real LaTeX); TextScript records
the in-effect size declaration and the argument parses with the outer
size cleared, so {\large ...} sets scripts at that size's own sf@size
with locally-computed shifts; textscript.rs now asserts the numeric
oracle shifts (sup2/sub1 at 10pt and 12pt, tall-subscript formula, the
{\large} case, footnote-mark sup2) instead of direction-only checks.

Implementation-Agent: muse-spark-1.3-contributor
@d-q222

d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Fix pushed (`0542a773`) addressing all 4 review findings, checked against the pdflatex oracle.

  • Finding 1: subscript drop is no longer "the superscript raise, negated". New `subscript_drop` implements the real `max(sub1, h − ⅘·x-height)` (TeXbook rule 18) with an independent `SUB1_DROP_EM`.
  • Finding 2: replaced sup1 (`0.412892`, display style) with sup2 (`0.362892`, text style) for both `\textsuperscript` and the shared `\footnotemark` path — footnote marks move to sup2 too, confirmed more correct (existing footnote-mark test still passes).
  • Finding 3: `TextScript` now records the local style at the command site and resolves size/shifts from that local size (via `sf_size`) instead of the ambient body size — `{\large a\textsuperscript{b}c}` now correctly sets `b` at 10pt with local shifts.
  • Finding 4: geometry tests rewritten with oracle-anchored numerics (12pt/10pt/`{\large}` cases) instead of direction-only checks.

Independently verified: 8/8 focused `textscript` tests pass, full `crates/compiler` suite 58/58 test binaries clean. Mutation check (fresh `CARGO_TARGET_DIR`, finding 2): reverted `SUP2_RAISE_EM` to the sup1 value → 4 of 8 tests FAILED with exactly the reported wrong numbers (`got 4.95, want oracle 4.354704`); restored → 8/8 pass.

Also fixed the stale "render-pipeline is PR #" placeholder in this PR's own body — now correctly says #508.

…d/textsuperscript-compiler

# Conflicts:
#	crates/compiler/src/parser.rs
#	crates/compiler/src/vocabulary.rs
#	docs/user/compiler.md
@d-q222

d-q222 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

daniel-muse-lead: merged origin/main, now MERGEABLE.

Merge (not rebase) origin/main. 3 conflicts: docs/user/compiler.md
(generated, regenerated via sh crates/compiler/scripts/render_supported_latex.sh),
crates/compiler/src/vocabulary.rs (real, needed care — see below), and
parser.rs (the now-familiar duplicate-code trap: this PR's old pre-refactor
big match arm vs. main's underline_command/text_mode_math_command split —
kept main's structure, re-added "textsuperscript" | "textsubscript" => self.text_script(...) to the new consolidated dispatch list).

The vocabulary.rs conflict was not a plain union. KNOWN_UNIMPLEMENTED_COMMANDS
on main still lists "textsuperscript"/"textsubscript" (correct for main,
which has no real dispatch for them), while this branch's own diff already
removes them from that list as part of implementing the real dispatch. A
blind union would have silently reintroduced the exact stale-entry bug found
elsewhere today (#701's marginpar, this session's addvspace) — kept this
branch's version, which correctly omits them, and did not touch main's
separate "underbar" entry (also stale, but that's #715's territory,
already claimed and in progress by daniel-muse-lead-2 — left it alone to
avoid stepping on that lane).

Literal test output, cargo test --test textscript (fresh CARGO_TARGET_DIR):

running 8 tests
test text_script_wraps_only_its_argument ... ok
test short_subscript_stays_on_sub1 ... ok
test text_scripts_match_text_style_oracle_at_body_size ... ok
test tall_subscript_uses_box_height_over_sub1 ... ok
test footnote_mark_uses_text_style_sup2 ... ok
test text_scripts_match_text_style_oracle_at_10pt ... ok
test text_scripts_typeset_with_no_diagnostics ... ok
test local_size_declaration_drives_script_size_and_shifts ... ok

test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s

Mutation check (re-run independently): routed the dispatch arm to
self.unsupported(name, span) — 7/8 tests fail (assertion failed: !BUILT_INS.contains(&name), the same debug-assert pattern seen elsewhere
today; 1 unrelated test passes); restored, git diff empty, 8/8 pass again.

Full crates/compiler suite (fresh target dir): all suites green, 0
failures.

Now MERGEABLE against main. Merge commit correctly authored as d-q222.

@d-q222
d-q222 merged commit b9e496a into main Sep 17, 2026
21 of 22 checks passed
d-q222 added a commit that referenced this pull request Sep 17, 2026
…ain f0f86aa

compiler 8a8a22b -> f0f86aa picks up #507 (\textsuperscript /
\textsubscript as Inline::TextScript), #783, #708, #781; tex-expansion
PIN only (no changes); bibliography unchanged. No local patches.
font-engine, tex-boxes, tex-text-encoding not moved (nothing needs them).

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent
Co-authored-by: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
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