From e74def23e79ce4317b48518fa6baf076bce92828 Mon Sep 17 00:00:00 2001 From: Alexandre Nunes Date: Sun, 20 Sep 2020 16:26:55 -0300 Subject: [PATCH] feat: add mmultiscripts prescript default case --- .../mathml-tags/MMultiscripts.ts | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/converters/mathml-interfaces-to-latex/mathml-tag-to-latex/mathml-tags/MMultiscripts.ts b/src/converters/mathml-interfaces-to-latex/mathml-tag-to-latex/mathml-tags/MMultiscripts.ts index 0664e89..780b898 100755 --- a/src/converters/mathml-interfaces-to-latex/mathml-tag-to-latex/mathml-tags/MMultiscripts.ts +++ b/src/converters/mathml-interfaces-to-latex/mathml-tag-to-latex/mathml-tags/MMultiscripts.ts @@ -8,7 +8,7 @@ export class MMultiscripts extends MathMLTag { } convert(): string { - if (this._children.length < 3) throw new InvalidNumberOfChild(this.name, 2, this._children.length, 'at least'); + if (this._children.length < 3) throw new InvalidNumberOfChild(this.name, 3, this._children.length, 'at least'); const base = this._children[0]; const sub = this._children[1]; @@ -20,7 +20,29 @@ export class MMultiscripts extends MathMLTag { const wrappedSub = new BracketWrapper().wrap(sub.convert()); const wrappedSup = new BracketWrapper().wrap(sup.convert()); - return `${this._wrapInParenthesisIfThereIsSpace(base.convert())}_${wrappedSub}^${wrappedSup}`; + return this._prescriptLatex() + this._wrapInParenthesisIfThereIsSpace(base.convert()) + this._postscriptLatex(); + } + + private _prescriptLatex(): string { + if (this._children[3]?.name !== 'mprescripts') return ''; + + const sub = this._children[4]; + const sup = this._children[5]; + + const subLatex = sub ? sub.convert() : ''; + const supLatex = sup ? sup.convert() : ''; + + return `\\_{${subLatex}}^{${supLatex}}`; + } + + private _postscriptLatex(): string { + const sub = this._children[1]; + const sup = this._children[2]; + + const subLatex = sub ? sub.convert() : ''; + const supLatex = sup ? sup.convert() : ''; + + return `_{${subLatex}}^{${supLatex}}`; } private _wrapInParenthesisIfThereIsSpace(str: string): string {