Skip to content

Commit

Permalink
fix: fixed #2121
Browse files Browse the repository at this point in the history
  • Loading branch information
arnog committed Sep 2, 2023
1 parent 311fcad commit 84c51c6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
- **#2122** On the Virtual Keyboard, the multiplication key now produces `\cdot` instead
of `\times`. Use shift to produce `\times`.
- Improved serialization to ASCIIMath and MathML
- **#2121** For ASCIIMath and MathML serialization, including phantom closing
delimiter in the output.

## 0.95.5 (2023-08-18)

Expand Down
12 changes: 8 additions & 4 deletions src/addons/math-ml.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Atom } from '../core/atom-class';
import { MacroAtom } from '../core-atoms/macro';
import { mathVariantToUnicode } from '../core-definitions/unicode';
import { LeftRightAtom } from '../core-atoms/leftright';

export type MathMLStream = {
atoms: Atom[];
Expand Down Expand Up @@ -792,18 +793,21 @@ function atomToMathML(atom, options): string {
break;

case 'leftright':
const leftrightAtom = atom as LeftRightAtom;
const lDelim = leftrightAtom.leftDelim;
result = '<mrow>';
if (atom.leftDelim && atom.leftDelim !== '.') {
if (lDelim && lDelim !== '.') {
result += `<mo${makeID(atom.id, options)}>${
SPECIAL_DELIMS[atom.leftDelim] ?? atom.leftDelim
SPECIAL_DELIMS[lDelim] ?? lDelim
}</mo>`;
}

if (atom.body) result += toMathML(atom.body, options);

if (atom.rightDelim && atom.rightDelim !== '.') {
const rDelim = leftrightAtom.matchingRightDelim();
if (rDelim && rDelim !== '.') {
result += `<mo${makeID(atom.id, options)}>${
SPECIAL_DELIMS[atom.rightDelim] ?? atom.rightDelim
SPECIAL_DELIMS[rDelim] ?? rDelim
}</mo>`;
}

Expand Down
38 changes: 17 additions & 21 deletions src/editor/atom-to-ascii-math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ const SPECIAL_OPERATORS = {
'\\rparen': ')',
'\\langle': '(:',
'\\rangle': ':)',
'\\sum': 'sum',
'\\prod': 'prod',
'\\bigcap': 'nnn',
'\\bigcup': 'uuu',
'\\int': 'int',
'\\oint': 'oint',
'\\sum': ' sum ',
'\\prod': ' prod ',
'\\bigcap': ' nnn ',
'\\bigcup': ' uuu ',
'\\int': ' int ',
'\\oint': ' oint ',
'\\ge': '>=',
'\\le': '<=',
'\\ne': '!=',
Expand All @@ -88,13 +88,13 @@ const SPECIAL_OPERATORS = {
'\\gt': '>',
'\\gets': '<-',
'\\to': '->',
'\\land': 'and',
'\\lor': 'or',
'\\lnot': 'not',
'\\forall': 'AA',
'\\exists': 'EE',
'\\in': 'in',
'\\notin': '!in',
'\\land': ' and ',
'\\lor': ' or ',
'\\lnot': ' not ',
'\\forall': ' AA ',
'\\exists': ' EE ',
'\\in': ' in ',
'\\notin': ' !in ',
'\\mapsto': '|->',
'\\implies': '=>',
'\\iff': '<=>',
Expand Down Expand Up @@ -239,15 +239,11 @@ export function atomToAsciiMath(atom: Atom | Atom[] | undefined): string {
case 'leftright':
{
const leftrightAtom = atom as LeftRightAtom;
result +=
leftrightAtom.leftDelim === '.' || !leftrightAtom.leftDelim
? '{:'
: leftrightAtom.leftDelim;
const lDelim = leftrightAtom.leftDelim;
result += lDelim === '.' || !lDelim ? '{:' : lDelim;
result += atomToAsciiMath(leftrightAtom.body);
result +=
leftrightAtom.rightDelim === '.' || !leftrightAtom.rightDelim
? ':}'
: leftrightAtom.rightDelim;
const rDelim = leftrightAtom.matchingRightDelim();
result += rDelim === '.' || !rDelim ? ':}' : rDelim;
}

break;
Expand Down

0 comments on commit 84c51c6

Please sign in to comment.