Implemented mpadded tag use cases and removed mrow

This commit is contained in:
Alexandre Nunes 2020-09-04 11:12:17 -03:00
parent f750e9f873
commit 84fbcb498e
5 changed files with 44 additions and 15 deletions

@ -490,4 +490,24 @@ describe('#convert', () => {
expect(result).toMatch('\\sqrt[3]{x + 2}');
});
});
describe('given math string with mpadded tag', () => {
test('parse mpadded just wrapping its content', () => {
const mathml = `
<root>
<math>
<mpadded>
<mn>2</mn>
<mo>+</mo>
<mn>2</mn>
</mpadded>
</math>
</root>
`;
const result = MathMLToLaTeX.convert(mathml);
expect(result).toMatch('2 + 2');
});
});
});

@ -1,4 +1,16 @@
import { Math, MathMLTag, MI, MO, MN, MSqrt, MRow, MSup, MFenced, MFrac, MRoot } from './mathml-tags';
import {
Math,
MathMLTag,
MI,
MO,
MN,
MSqrt,
MSup,
MFenced,
MFrac,
MRoot,
GenericContentWrapperTag,
} from './mathml-tags';
export class Dispatcher {
private _name: string;
@ -25,8 +37,6 @@ export class Dispatcher {
return new MN(this._value, this._attributes, this._children);
case 'msqrt':
return new MSqrt(this._value, this._attributes, this._children);
case 'mrow':
return new MRow(this._value, this._attributes, this._children);
case 'msup':
return new MSup(this._value, this._attributes, this._children);
case 'mfenced':
@ -35,6 +45,9 @@ export class Dispatcher {
return new MFrac(this._value, this._attributes, this._children);
case 'mroot':
return new MRoot(this._value, this._attributes, this._children);
case 'mrow':
case 'mpadded':
return new GenericContentWrapperTag(this._name, this._value, this._attributes, this._children);
default:
return new MathMLTag(this._name, this._value, this._attributes, this._children);
}

@ -0,0 +1,7 @@
import { MathMLTag } from './MathMLTag';
export class GenericContentWrapperTag extends MathMLTag {
convert(): string {
return this._mapChildrenToLaTeX().join(' ');
}
}

@ -1,11 +0,0 @@
import { MathMLTag } from './MathMLTag';
export class MRow extends MathMLTag {
constructor(value: string, attributes: Record<string, string>, children: MathMLTag[]) {
super('mrow', value, attributes, children);
}
convert(): string {
return this._mapChildrenToLaTeX().join(' ');
}
}

@ -4,8 +4,8 @@ export { MI } from './MI';
export { MO } from './MO';
export { MN } from './MN';
export { MSqrt } from './MSqrt';
export { MRow } from './MRow';
export { MSup } from './MSup';
export { MFenced } from './MFenced';
export { MFrac } from './MFrac';
export { MRoot } from './MRoot';
export { GenericContentWrapperTag } from './GenericContentWrapperTag';