Skip to content

feat(math): implement m:sSub subscript converter (SD-2373)#2635

Merged
caio-pizzol merged 2 commits intosuperdoc-dev:mainfrom
gpardhivvarma:feat/math-ssub-subscript-converter
Mar 31, 2026
Merged

feat(math): implement m:sSub subscript converter (SD-2373)#2635
caio-pizzol merged 2 commits intosuperdoc-dev:mainfrom
gpardhivvarma:feat/math-ssub-subscript-converter

Conversation

@gpardhivvarma
Copy link
Copy Markdown
Contributor

Summary

  • Add OMML m:sSub β†’ MathML <msub> converter following the fraction.ts pattern
  • Move m:f from the "not yet implemented" registry section to "implemented" where it belongs
  • 3 tests: basic conversion (a₁), properties element ignored, missing m:sub graceful degradation

Test plan

  • pnpm --filter @superdoc/painter-dom test β€” omml-to-mathml.test.ts passes (17 tests)
  • Upload sd-2373-subscript.docx to dev app and verify subscript renders correctly

Closes #2596

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ’‘ Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 375438e41c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 πŸ‘.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +22 to +23
msub.appendChild(convertChildren(base?.elements ?? []));
msub.appendChild(convertChildren(sub?.elements ?? []));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Wrap m:sSub operands before appending to

convertChildren(base?.elements ?? []) and convertChildren(sub?.elements ?? []) append raw operand fragments directly into <msub>, so any multi-token base/subscript (for example (a+b)_n) produces more than two direct children. MathML script elements are binary and expect exactly base+subscript nodes, so these cases become structurally invalid and can render with dropped/mis-associated tokens. Wrap each operand in an <mrow> (or convert m:e/m:sub as units) before appending.

Useful? React with πŸ‘Β / πŸ‘Ž.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gpardhivvarma confirmed β€” we'll fix this across all converters in a follow-up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed β€” operands are now wrapped in <mrow> before appending, matching the pattern in bar.ts. Multi-part expressions like x_{n+1} now produce exactly 2 children in <msub>. Added a test for this case too.

Copy link
Copy Markdown
Contributor

@caio-pizzol caio-pizzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gpardhivvarma nice work β€” follows the existing pattern well and the spec reference is correct.

simple subscripts like a₁ render correctly. when the base or subscript has multiple parts (like x_{n+1}), they don't get grouped properly and the rendering breaks. fraction.ts has the same issue β€” bar.ts already handles it. we'll fix all converters together in a follow-up.

tests look good.

i made a .docx with 10 subscript variations:

sd-2373-subscript-edge-cases-v2.docx

# expression works?
1 a₁ yes
2 x_{n+1} no β€” 4 children instead of 2
3 (a+b)_n no β€” 4 children instead of 2
4 (a+b)_{n+1} no β€” 6 children instead of 2
5 x_{i+j+k+1} no β€” 8 children instead of 2
6 a_{b_c} (nested) yes
7 x_{a/b} (fraction) yes
8 yβ‚€ (with properties) yes
9 a₁+bβ‚‚ (multiple) yes
10 x_{} (empty) no β€” 1 child instead of 2

Word:
image

SuperDoc:
image

simple cases (1, 6-9) look the same. multi-part cases (2-5) render incorrectly in SuperDoc.

left an inline comment.

@caio-pizzol caio-pizzol self-assigned this Mar 30, 2026
Add OMML m:sSub β†’ MathML <msub> converter following the fraction.ts
pattern. Also move m:f from the "not yet implemented" registry section
to "implemented" where it belongs.

Closes superdoc-dev#2596
Converters for msub, mfrac were appending raw DocumentFragments
directly, causing multi-token expressions (e.g. n+1) to produce
too many direct children. MathML script/fraction elements require
exactly 2 children. Wrap each operand in <mrow> to group them,
matching the pattern already used by bar.ts.
@gpardhivvarma gpardhivvarma force-pushed the feat/math-ssub-subscript-converter branch from 71c5170 to feab86a Compare March 31, 2026 09:51
Copy link
Copy Markdown
Contributor

@caio-pizzol caio-pizzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gpardhivvarma the grouping fix works β€” tested 15 edge cases and everything renders correctly now. you also fixed the same issue in fraction.ts which is a nice bonus.

uploaded the edge case test file to our test corpus so we catch regressions going forward.

approving.

@caio-pizzol caio-pizzol merged commit 2cc3abb into superdoc-dev:main Mar 31, 2026
47 checks passed
@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot bot commented Mar 31, 2026

πŸŽ‰ This PR is included in template-builder v1.3.0-next.10

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot bot commented Mar 31, 2026

πŸŽ‰ This PR is included in vscode-ext v1.1.0-next.53

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot bot commented Mar 31, 2026

πŸŽ‰ This PR is included in esign v2.2.0-next.11

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot bot commented Mar 31, 2026

πŸŽ‰ This PR is included in superdoc-cli v0.5.0-next.50

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot bot commented Mar 31, 2026

πŸŽ‰ This PR is included in superdoc-sdk v1.3.0-next.51

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot bot commented Mar 31, 2026

πŸŽ‰ This PR is included in superdoc v1.24.0-next.50

The release is available on GitHub release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Math: implement m:sSub subscript converter (community)

2 participants