Skip to content

Commit 35c7063

Browse files
committed
feat: multiline serialization to MathML
1 parent ddde57a commit 35c7063

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050

5151
### Resolved Issues
5252

53+
- Fixed MathML serialization for multiline mathfields. Previously, serializing
54+
multiline mathfields (such as `\displaylines{\\ }`) to MathML would result in
55+
invalid MathML with syntax errors and console warnings. The fix corrects a
56+
syntax error in array delimiter serialization and properly handles line break
57+
(`\\`) atoms in multiline environments by skipping them (since line breaks are
58+
represented by the `<mtr>` table structure in MathML, not by explicit line
59+
break atoms).
5360
- **#2146** Fixed nested subscript and superscript creation when using physical
5461
keyboard shortcuts (`Shift+-`, `Ctrl+-`). Previously, typing `a_b_` would
5562
highlight `b` and reuse the outer subscript instead of creating a subscript of

src/formats/atom-to-math-ml.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,16 @@ function atomToMathML(atom: Atom, options: { generateID?: boolean }): string {
724724
switch (atom.type) {
725725
case 'first':
726726
break; // Nothing to do
727+
case 'error':
728+
// Line breaks (\\) in multiline environments are represented by the table structure
729+
// in MathML, so we don't need to output anything for them
730+
if (atom.command === '\\\\') break;
731+
// For other error atoms, wrap in merror
732+
result = `<merror${makeID(atom.id, options)}>${toMathML(
733+
atom.body,
734+
options
735+
)}</merror>`;
736+
break;
727737
case 'group':
728738
case 'root':
729739
result = toMathML(atom.body, options);
@@ -772,7 +782,7 @@ function atomToMathML(atom: Atom, options: { generateID?: boolean }): string {
772782
(arrayAtom.rightDelim && arrayAtom.rightDelim !== '.')
773783
) {
774784
if (arrayAtom.rightDelim && arrayAtom.rightDelim !== '.')
775-
result += `'<mo>${SPECIAL_DELIMS[arrayAtom.rightDelim!] || arrayAtom.rightDelim}</mo>`;
785+
result += `<mo>${SPECIAL_DELIMS[arrayAtom.rightDelim!] || arrayAtom.rightDelim}</mo>`;
776786

777787
result += '</mrow>';
778788
}

0 commit comments

Comments
 (0)