Repository navigation
compiler: text-mode phantom/hphantom/vphantom as invisible hboxes (#494) - #878
Conversation
Text mode rejected \phantom/\hphantom/\vphantom with
error[unsupported_feature] and typeset the argument as plain visible
text -- the worst kind of wrong, since the recovery made the argument
show up rather than reserving invisible space. Math mode already had
Nucleus::Phantom (math.rs); this adds the text-mode mirror with the
exact same flags (horizontal false only for vphantom, vertical false
only for hphantom).
New Inline::Phantom keeps the braced argument as an hbox so each layout
measures the real typeset extent in its own metrics (baking parser-time
pt values in would mix Core 14's Times metrics into the render
pipeline's Latin-Modern/CM TFM metrics). The Core 14 layout measures via
measure_phantom/measure_into (a per-variant mirror of the emit arms:
text, math, rules, kerns/glue, nested wrappers, transparent wrappers)
and advances like an unpainted rule strut: nothing painted, correct
width/height/depth reserved.
Inventory: BUILT_INS + TEXT_COMMANDS rows added; removed from
KNOWN_UNIMPLEMENTED_COMMANDS; regenerated supported-latex.json,
docs/user/compiler.md and the Mac bundle copy via the repo's own
generator.
crates/compiler only. Render-pipeline support (an Item::Phantom mirroring
the existing Underline arm, plus a non-painting BoxRec::Rule{0,0,0} the
way struts already use) needs the next vendor/compiler re-pin before it
reaches CLI/render-pipeline users -- the pin lags main by commits
including other in-flight lanes' work, so re-pinning here would entangle
unrelated integration. Not done in this change.
Implementation-Agent: muse-spark-1.3-contributor (Muse Code)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)
Co-authored-by: d-q222 <[email protected]>
jay3332
left a comment
There was a problem hiding this comment.
mac-claude-a verification: Reviewed diff (compiler-only: parser.rs, layout.rs, incremental.rs, supported.rs/vocabulary.rs, docs; no render-pipeline/vendor touched, matching the PR's claim — render-pipeline's few phantom hits are pre-existing Nucleus::Phantom math handling, unrelated). No pre-existing test expectations changed, no unwrap/expect added on data paths, no unexplained magic numbers.
Ran crates/compiler/tests/text_phantom.rs (added by this PR): 10/10 pass. Wrote a throwaway test reproducing GH-494 exactly (Text \phantom{X} more \hphantom{Y} end \vphantom{Z} done) via compile_full: 0 diagnostics, X/Y/Z never appear in visible output, and "more" advances from x=95.98pt (no phantom) to x=107.64pt (with phantom) — spacing correctly reserved. Cross-checked with pdflatex (TeX Live 2026) as oracle: same source compiles cleanly (exit 0, no errors), confirming valid LaTeX and consistent with standard \phantom semantics. text_phantom.rs::hphantom_keeps_width_drops_height / vphantom_drops_width_keeps_height confirm width-only vs height-only flag semantics match math.rs's Nucleus::Phantom exactly (same horizontal/vertical flag convention, verified by reading math.rs:5338-5352).
Full cargo test for the crate did not finish in this session due to heavy CPU contention from ~15 concurrent review-agent cargo processes on this machine (unrelated to the PR); targeted new-test results above are conclusive.
No blockers found.
Summary
\phantom/\hphantom/\vphantomwitherror[unsupported_feature], and the recovery path typeset the braced argument as plain visible text — the worst kind of wrong, since the argument showed up instead of reserving invisible space. Math mode already implements all three (Nucleus::Phantominmath.rs); this adds the text-mode mirror with identical flags (horizontalfalse only for\vphantom,verticalfalse only for\hphantom).Inline::Phantomkeeps the braced argument as an hbox so each layout measures the real typeset extent in its own metrics (baking parser-time pt values in would mix Core 14's Times metrics into the render pipeline's Latin-Modern/CM TFM metrics). The Core 14 layout measures via newmeasure_phantom/measure_into(a per-variant mirror of the existingemitarms) and advances like an unpainted rule strut: nothing painted, correct width/height/depth reserved.BUILT_INS,TEXT_COMMANDS, pruned fromKNOWN_UNIMPLEMENTED_COMMANDS), generated docs/JSON regenerated via the repo's own generator script.crates/compileronly. Render-pipeline support (anItem::Phantommirroring the existingUnderlinearm) needs the nextvendor/compilerre-pin before it reaches CLI/render-pipeline users — deliberately not done here since the pin currently lagsmainby other in-flight lanes' work.Test plan
crates/compiler/tests/text_phantom.rs(10 tests): issue repro (zero diagnostics, argument absent from visible output), node shape/flags for all three commands, advance-equality against visible references (\text,\rule, a zero-width strut), styled/math/nested-argument cases, empty/missing-argument edges, lone-phantom-body page reservation, math-mode formulae unchanged.crates/compilersuite: 88 targets, 0 failed.Implementation by
muse-spark-1.3-contributor(Muse Code), supervised and independently re-verified bydaniel-muse-lead(Claude Sonnet) against git diff/log and a fresh local test run before publishing via thepublish-lane.shgated workflow.🤖 Generated with Claude Code