fix: wrap vcenter mpadded in mrow for valid MathML#4193
fix: wrap vcenter mpadded in mrow for valid MathML#4193grigoriy-reshetniak merged 3 commits intoKaTeX:mainfrom
Conversation
Fix invalid MathML structure when \vcenter is used inside \mathrel.
Previously, \mathrel{\vcenter{:}} produced <mo><mpadded>...</mpadded></mo>,
which is invalid because <mpadded> cannot be a child of <mo>.
Now wraps the <mpadded> in an <mrow>, producing valid MathML:
<mo><mrow><mpadded>...</mpadded></mrow></mo>
Fixes KaTeX#4078
Greptile SummaryThis PR fixes invalid MathML output when Confidence Score: 5/5Safe to merge; the fix is minimal, correct, and all 1270 existing tests pass. The change is a targeted two-liner that wraps mpadded in mrow, directly matching the MathML content-model spec. No existing behavior is altered for standalone vcenter usage since mrow is semantically transparent. The only remaining feedback is a P2 suggestion to add a regression test, which does not block merge. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["\\mathrel{\\vcenter{...}}"] --> B["mclass mathmlBuilder"]
B --> C["mo node"]
C -->|"Before fix"| D["mpadded.vcenter ❌ invalid child of mo"]
C -->|"After fix"| E["mrow"]
E --> F["mpadded.vcenter ✓ valid per MathML spec"]
Reviews (1): Last reviewed commit: "fix: wrap vcenter mpadded in mrow for va..." | Re-trigger Greptile |
| const mpadded = new MathNode( | ||
| "mpadded", [mml.buildGroup(group.body, options)], ["vcenter"]); | ||
| return new MathNode("mrow", [mpadded]); |
There was a problem hiding this comment.
Missing regression test for the fixed scenario
No test currently asserts the MathML structure when \vcenter is nested inside \mathrel (or \mathbin, \mathord, etc.) — the exact bug being fixed. Adding a test that renders \mathrel{\vcenter{\frac{a}{b}}} and checks that the output does not contain <mo><mpadded (bare mpadded inside mo) would guard this path against future regressions.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4193 +/- ##
==========================================
+ Coverage 93.15% 93.32% +0.16%
==========================================
Files 91 91
Lines 6795 6812 +17
Branches 1582 1585 +3
==========================================
+ Hits 6330 6357 +27
- Misses 429 453 +24
+ Partials 36 2 -34
... and 15 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
edemaine
left a comment
There was a problem hiding this comment.
As Grigoriy has pointed out, this is potentially suboptimal if \vcenter isn't nested inside something, but I think it's fine to take this simpler approach. I do wonder whether other macros need a similar treatment... but can worry about that another time.
|
Thank you! |
|
🎉 This PR is included in version 0.16.45 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [katex](https://katex.org) ([source](https://github.com/KaTeX/KaTeX)) | [`0.16.44` → `0.16.45`](https://renovatebot.com/diffs/npm/katex/0.16.44/0.16.45) |  |  | --- ### Release Notes <details> <summary>KaTeX/KaTeX (katex)</summary> ### [`v0.16.45`](https://github.com/KaTeX/KaTeX/blob/HEAD/CHANGELOG.md#01645-2026-04-05) [Compare Source](KaTeX/KaTeX@v0.16.44...v0.16.45) ##### Bug Fixes - wrap vcenter mpadded in mrow for valid MathML ([#​4193](KaTeX/KaTeX#4193)) ([ee66b78](KaTeX/KaTeX@ee66b78)), closes [#​4078](KaTeX/KaTeX#4078) </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDQuOCIsInVwZGF0ZWRJblZlciI6IjQzLjEwNC44IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Co-authored-by: Renovate Bot <[email protected]> Co-committed-by: Renovate Bot <[email protected]>
Fixes #4078
Problem
When
\vcenteris used inside\mathrel(and similar commands), the resulting MathML is invalid:The issue is that
<mpadded>cannot be a direct child of<mo>per the MathML spec.Solution
Wrap the
<mpadded>element in an<mrow>to produce valid MathML:Changes
src/functions/vcenter.tsto wrapmpaddedinmrowTesting