Skip to content

Commit 48a74f9

Browse files
authored
fix(math): set displaystyle and Cambria Math font on MathML output (SD-2404) (#2622)
Set displaystyle=true only on display math (m:oMathPara) per ECMA-376 spec — inline math uses cramped mode with smaller fractions and limits as subscripts. Set display=block for m:oMathPara. Use Cambria Math as preferred math font to match Word rendering.
1 parent a5ba5f6 commit 48a74f9

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

packages/layout-engine/painters/dom/src/features/math/omml-to-mathml.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ describe('convertOmmlToMathml', () => {
3030
expect(result).not.toBeNull();
3131
expect(result!.namespaceURI).toBe(MATHML_NS);
3232
expect(result!.localName).toBe('math');
33+
expect(result!.getAttribute('displaystyle')).toBeNull();
34+
expect(result!.getAttribute('display')).toBeNull();
3335

3436
// Should contain an <mi> for the identifier 'x'
3537
const mi = result!.querySelector('mi');
@@ -94,6 +96,8 @@ describe('convertOmmlToMathml', () => {
9496
const result = convertOmmlToMathml(omml, doc);
9597
expect(result).not.toBeNull();
9698
expect(result!.localName).toBe('math');
99+
expect(result!.getAttribute('displaystyle')).toBe('true');
100+
expect(result!.getAttribute('display')).toBe('block');
97101
// The m:oMathParaPr should be skipped (it ends with 'Pr')
98102
// The m:oMath child should produce content
99103
expect(result!.textContent).toBe('y');

packages/layout-engine/painters/dom/src/features/math/omml-to-mathml.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ export function convertOmmlToMathml(ommlJson: unknown, doc: Document): Element |
157157

158158
const root = ommlJson as OmmlJsonNode;
159159
const mathEl = doc.createElementNS(MATHML_NS, 'math');
160+
mathEl.setAttribute('style', 'font-family: "Cambria Math", math');
161+
162+
if (root.name === 'm:oMathPara') {
163+
mathEl.setAttribute('display', 'block');
164+
mathEl.setAttribute('displaystyle', 'true');
165+
}
160166

161167
// For m:oMathPara, iterate over child m:oMath elements
162168
// For m:oMath, process directly

0 commit comments

Comments
 (0)