UNPKG

az-mathml-to-latex

Version:

A JavaScript tool to convert mathml string to LaTeX string

30 lines (29 loc) 1.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MSubsup = void 0; var helpers_1 = require("../../../helpers"); var errors_1 = require("../../../errors"); var MSubsup = /** @class */ (function () { function MSubsup(mathElement) { this._mathmlElement = mathElement; } MSubsup.prototype.convert = function () { var _a = this._mathmlElement, name = _a.name, children = _a.children; var childrenLength = children.length; if (childrenLength !== 3) throw new errors_1.InvalidNumberOfChildrenError(name, 3, childrenLength); var base = helpers_1.mathMLElementToLaTeXConverter(children[0]).convert(); var sub = helpers_1.mathMLElementToLaTeXConverter(children[1]).convert(); var sup = helpers_1.mathMLElementToLaTeXConverter(children[2]).convert(); var wrappedSub = new helpers_1.BracketWrapper().wrap(sub); var wrappedSup = new helpers_1.BracketWrapper().wrap(sup); return this._wrapInParenthesisIfThereIsSpace(base) + "_" + wrappedSub + "^" + wrappedSup; }; MSubsup.prototype._wrapInParenthesisIfThereIsSpace = function (str) { if (!str.match(/\s+/g)) return str; return new helpers_1.ParenthesisWrapper().wrap(str); }; return MSubsup; }()); exports.MSubsup = MSubsup;