Skip to content

render-pipeline: \textsuperscript/\textsubscript raised at sf@size (needs #507 re-pin) - #508

Closed
d-q222 wants to merge 2 commits into
mainfrom
agent/daniel-muse-lead/textsuperscript-pipeline
Closed

d-q222 wants to merge 2 commits into
mainfrom
agent/daniel-muse-lead/textsuperscript-pipeline

Conversation

@d-q222

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

Copy link
Copy Markdown
Contributor

Scope

Part 2 of 2 for #497 — blocked on PR #507 landing and a vendor/compiler re-pin. This PR intentionally does NOT touch vendor/ (out of my delegated scope); until someone re-pins crates/render-pipeline/vendor/compiler after #507 merges, this branch will not build (Inline::TextScript doesn't exist in the current vendored snapshot) — confirmed and expected, the same "needs re-pin" state as #137/#138.

New adapter::Item::TextScript lowered from the compiler variant; typeset::textscript_box lays it out at footnotes::script_size (the same \DeclareMathSizes-derived size footnote marks use), with a sup2-based raise for superscripts (the footnote-mark shift) and an Appendix-G rule-18 drop for subscripts. New BoxRec::TextScript merged as an unbreakable run.

Overlap check

git branch -a --list '*textsuperscript*' '*textscript*' — only this lane's own branches.

Test results

Cannot run yet — build fails with error[E0599]: no variant ... TextScript found for enum Inline at 4 call sites in adapter.rs, exactly the missing-vendor-mirror failure mode, confirmed by the reviewer (nothing else broken). Once #507 lands and vendor/compiler is re-pinned, the implementer's own results (not yet independently reverified, since the build doesn't work standalone) were: crates/render-pipeline/tests/textscript.rs 4/4 passing, geometry asserted numerically (script runs at 7.0pt/\sf@size at 10pt body size; superscript lifted ~3.63pt/sup2; subscript dropped ~1.5pt/sub1; math scripts $x^2_3$ unaffected), mutation check reported clean. Re-verify all of this independently once the re-pin lands, before marking ready — do not trust this paragraph alone.

Not done

Same follow-ups as #507 (headings/captions/table cells, nested styling, size classes). A separately-noted pre-existing bug (debug_assert_eq! panic in debug-mode cargo test for ANY box-argument command, verified to reproduce identically on a pristine \uline call via git stash — i.e. not introduced by this change) is out of scope here; worth its own issue.

🤖 Generated with Claude Code

#497)

New adapter Item::TextScript lowered from Inline::TextScript; typeset
lays the mbox out at footnotes::script_size (DeclareMathSizes, as marks
use) and shifts it by a new TextScript box record: sup2-based raise for
superscripts (same as footnote marks), rule-18 sub1/sub_drop-based drop
for subscripts (same formula as the LaTeXe epsilon). Assembly paints
the inner line shifted; span arms added everywhere BoxRec is matched.

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 (keep it draft until #507 lands and vendor/compiler is re-pinned; there are also geometry bugs below)

Reviewed head ac5bc14f. muse-precheck.sh 508: no hard-rule violations and no vendor/ paths. CI rust render-pipeline and rust flashtex-cli fail, which is expected without the re-pin.

How I built it without touching vendor/:

Results with that build:

  • Default (debug) cargo test --test textscript: all 4 tests panic at src/adapter.rs:1275 (debug_assert_eq!(leadings.len(), parsed.blocks.len()), left: 3 right: 1). An ab \underline{x} cd document panics the same way (left: 2 right: 1), which fits the body's "pre-existing" note.
    • Before this can go green in CI, someone has to fix that assert or show that CI's configuration doesn't hit it. As is, the new tests cannot pass a debug run.
  • With CARGO_PROFILE_{DEV,TEST}_DEBUG_ASSERTIONS=false: test result: ok. 4 passed; 0 failed.

Oracle: /Library/TeX/texbin/pdflatex, article 10pt, \showbox. \@textsuperscript = $^{\mbox{\fontsize\sf@size\z@\selectfont #1}}$. Pipeline numbers are display-list bp.

  1. The body case at 10pt is correct.
    • E=mc\textsuperscript{2}: runs at 6.974bp (7pt), raised 3.616bp = 3.629pt (pdflatex shifted -3.62892).
    • H\textsubscript{2}: dropped 1.494bp = 1.500pt (pdflatex 1.49998).
    • x\textsubscript{(g)}: dropped 1.798bp = 1.806pt (pdflatex 1.80557).
  2. crates/render-pipeline/src/typeset.rs:4507-4509, 4571-4575 + adapter.rs:6622-6641: the script ignores a local size change.
    • textscript_box takes the block size. The adapter builds the content with the block size, and TextScriptItem carries no style, so the inner items keep their own \large/\small size and are never reduced.
    • Input {\large a\textsuperscript{b}c H\textsubscript{2}O} (10pt article):
      • pipeline: "b" at 11.955bp (12pt), raised 3.615bp; "2" at 12pt, dropped 4.097bp.
      • pdflatex: cmr/m/n/8, shifted -4.3547; "2" cmr/m/n/8, shifted 1.79999.
    • The bare declaration \large a\textsuperscript{b}c … gives the same wrong result.
    • Input {\small …}:
      • pipeline: scripts at 8.966bp (9pt), raised 3.615bp, dropped 2.242bp.
      • pdflatex: cmr/m/n/6, -3.82329, 0.99998.
  3. typeset.rs:4507-4588: the box width leaves out \scriptspace.
    • TeX adds \scriptspace (0.5pt) to every script box. pdflatex \hbox(4.51111+0.0)x4.48613 = cmr7 "2" 3.98612 + 0.5.
    • Input E=mc\textsuperscript{2} H\textsubscript{2}O: "H" is at x=183.263bp. pdflatex puts it about 0.50bp further right.
    • "O" follows the subscript by 3.971bp; pdflatex has 4.470bp.
    • Every text script is 0.5pt too narrow, and the error accumulates along the line.
  4. crates/render-pipeline/src/typeset/footnotes.rs:167-188: textsub_shift_pt hard-codes sub1 = 0.15em and x-height = 0.430555em.
    • sup2_pt right above already switches per lmsy design size, but the subscript side does not.
    • pdflatex \small (9pt) drop is 0.99998 (the formula gives 1.35). \footnotesize (8pt) is 1.1111 (the formula gives 1.20).
    • So \footnote{H\textsubscript{2}O} and any small-size text will be off once finding 2 is fixed.
  5. The tests only exercise \normalsize 10pt, so findings 2-4 pass unnoticed.
    • The 0.3pt tolerances on lift/drop (tests/textscript.rs:119, 134) are wide.
    • math_mode_scripts_are_unaffected only checks that runs containing x and 2 exist. It would pass if math scripts moved.
    • Please add numeric cases for {\large …}, \small, the next-glyph x (scriptspace) and a footnote.
  6. Body.
  7. Overlap.

What is fine:

  • Reusing sup2_pt (per design size).
  • The rule-18 subscript formula shape.
  • Treating the script as one unbreakable box with shift-inclusive height/depth.
  • Span plumbing through floatpage/multicol/assemble.

…#508)

Review slice 2 against the pdflatex showbox oracle. sup2_pt was
already correct (verified against lmsy7/8/10 TFMs and the oracle:
3.62892/4.3547/3.82329pt) so superscripts are untouched.

- footnotes: new sub1_pt/sub_drop_pt per-lmsy-design tables mirroring
  sup2_pt (sub1 0.2/0.166667/0.142858/0.125/0.111111/0.15,
  sub_drop 0.1/0.083333/0.071428/0.0625/0.055556/0.05); the 9pt drop is
  now 1.0pt not 1.35pt and the 8pt drop 1.1111pt not 1.2pt. x-height
  stays one constant (0.430555em at every lmsy design, per TFM).
- typeset: textscript_box advances content plus SCRIPT_SPACE (0.5pt),
  like footnote_mark; TfmLogoMetrics::math_sub_params reuses the
  shared helpers so the LaTeXe epsilon drops identically.
- tests/textscript.rs: oracle cases for large/small/footnotesize,
  a scriptspace residual check, and a footnote-mark guard.

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

d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Slice 2 pushed (`b467b5ea`), addressing findings 2 and 3 (finding 1's sup2 constant was already correct — cross-checked three ways against real TFM bytes, no change needed there).

  • Finding 2: new per-design-size `sub1_pt`/`sub_drop_pt` tables in `footnotes.rs`, mirroring the existing `sup2_pt` pattern. Values read directly from the vendored lmsy7/8/10 TFMs and embedded cmsy5/6/9 fix-words (lmsy is a metric copy of cmsy). `textsub_shift_pt` is now `max(sub_drop@size, sub1@size, h−4/5·ex)`.
  • Finding 3: `textscript_box` now adds the existing `SCRIPT_SPACE` (0.5pt) constant to the outer advance, same as `footnote_mark` already does.
  • Finding 4: 5 new geometry tests with tighter tolerances (±0.1, down from the flagged ±0.3).

Independently verified: no `vendor/` touch, diff scoped to `typeset.rs`/`footnotes.rs`/`tests/textscript.rs` only. Build still fails identically to before this slice — same 4 `error[E0599]` for the missing `TextScript` variant, confirming no new build errors, still cleanly blocked on the sibling #507's re-pin. Spot-checked the hand arithmetic: 9pt sub1 (1.0) matches the oracle's 0.99998, 8pt height-term arm (1.1111) matches exactly — consistent with the lane's own claimed TFM-byte cross-checks.

Still draft, still needs #507 + a re-pin before it can build/test for real.

@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #795 (ea179ef, Commander's direct-to-main \textsuperscript/\textsubscript implementation), per #2 (comment).

The one genuine gap this PR found beyond what's already shipped — the missing sub_drop term in the subscript-drop formula — is ported separately in #802, per that same ruling.

@d-q222 d-q222 closed this Sep 17, 2026
ItsAkilesh pushed a commit to ItsAkilesh/flashtex that referenced this pull request Sep 18, 2026
Per Commander's flash-tex#508 ruling (flash-texGH-508 review, superseded by ea179ef/flash-tex#795's
direct-to-main \textsuperscript/\textsubscript implementation): the shipped
`text_script_box` computed the subscript drop as a two-way
`sub1_pt(local).max(ht - 0.8*x_height)`, but Appendix G rule 18a-b's real
formula is a three-way max. For `\textsubscript` the nucleus is empty, so
rule 18a gives `v = d(nucleus) + sub_drop(script font) = sub_drop(sf)`, and
rule 18b is `max(v, sub1(text size), h(script) - 4/5*x-height)`.

Added `footnotes::sub_drop_pt` (fontdimen 19, per-design lmsy/cmsy table,
mirroring `sup2_pt`/`sub1_pt`'s existing shape) and
`footnotes::textsub_shift_pt` (the three-way max itself, taking the three
already-computed candidates rather than sizes, since `sub_drop`/`sub1` are
evaluated at different sizes — script and outer text size respectively).
`text_script_box` now calls it instead of the bare two-way max.

Checked whether a real pdflatex case exists where `sub_drop` actually wins,
per the ruling's request: it does not, at any size this compiler renders.
`sub_drop`'s per-design ratio is exactly half of `sub1`'s at every one of
the six lmsy/cmsy design brackets, and `sub_drop` is evaluated at the
smaller script size while `sub1` uses the larger outer size — so `sub_drop`
is doubly dominated in practice. `tests/text_script_oracle.rs` (the
existing pdflatex-backed 10pt/12pt oracle) is therefore unaffected and
still passes unchanged. Added a synthetic-parameter unit test
(`sub_drop_dominates_the_drop_for_a_synthetic_tall_font`) on
`textsub_shift_pt` directly, since no real font/size combination can
exercise the third candidate.

`\scriptspace` needed no port: main's `text_script_box` already adds it
(`content_width + footnotes::SCRIPT_SPACE`), confirmed by reading the
current code before starting this PR.

Tests: `crates/render-pipeline --lib`: 173 passed, 0 failed, 1 ignored
(1 new). `text_script_oracle`: 2/2, unchanged. Full `cargo test` (every
binary, niced): green. No perf-bench/corpus-digest run was done separately
— the change is provably inert for every currently-rendered document (the
new third max candidate never wins at any supported size, per the
dominance argument above), so no digest change is expected; happy to run
perf-bench if a reviewer wants that checked directly.

Implementation-Agent: daniel-muse-lead (Claude Sonnet)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
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