feat(math): implement m:phant phantom converter#2749
feat(math): implement m:phant phantom converter#2749Abdeltoto wants to merge 3 commits intosuperdoc-dev:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 566fc42ea0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
packages/layout-engine/painters/dom/src/features/math/converters/phantom.ts
Outdated
Show resolved
Hide resolved
packages/layout-engine/painters/dom/src/features/math/converters/phantom.ts
Outdated
Show resolved
Hide resolved
3e7e2c0 to
c6b8cc6
Compare
caio-pizzol
left a comment
There was a problem hiding this comment.
@Abdeltoto thanks for contributing this! the phantom converter is a nice addition and the code is clean — matches Word perfectly on 7 out of 10 test cases.
one thing to fix: when <m:show> is missing, content renders invisible but should be visible. this affects the most common phantom pattern (zeroing a dimension without explicitly setting show). left an inline comment with a one-line fix, comparison screenshots, and 10 Word-native test files.
| /** OOXML ST_OnOff true values. */ | ||
| const isOnOffTrue = (val?: string) => val === '1' || val === 'on' || val === 'true'; | ||
|
|
||
| const isVisible = isOnOffTrue(show?.attributes?.['m:val']) || (show != null && !show.attributes); |
There was a problem hiding this comment.
when <m:show> is missing from the phantom properties, the content should be visible — but right now it renders invisible. this is because both sides of the OR are false when show is undefined.
this breaks the most common phantom use case: zeroing descent without hiding content (the example in the spec). I tested 10 Word-native .docx files covering every property combination — these three don't match Word:
| file | what happens | should happen |
|---|---|---|
| phantom-01 (no properties) | content hidden | content shown |
| phantom-03 (zeroed descent) | content hidden inside radical | content shown inside radical |
| phantom-09 (fraction + zeroed descent) | content hidden | content shown |
| const isVisible = isOnOffTrue(show?.attributes?.['m:val']) || (show != null && !show.attributes); | |
| const isVisible = show == null || isOnOffTrue(show?.attributes?.['m:val']) || (show != null && !show.attributes); |
tests 1 and 4 will need updating too — they expect the current (wrong) behavior.
test files attached below if you want to verify locally.
phantom-test-files.zip




Closes #2608
Summary
m:phantOMML-to-MathML converter (invisible spacing placeholder)<mphantom>; partial dimension control maps to<mpadded>with zeroed width/height/depthm:show,m:zeroWid,m:zeroAsc, andm:zeroDescproperty flagsMATH_OBJECT_REGISTRYSpec reference
ECMA-376 Section 22.1.2.81
Test plan
vitest runpasses for omml-to-mathml.test.ts