UNPKG

@qtikit/mathml-to-latex

Version:

A JavaScript tool to convert mathml string to LaTeX string

30 lines (29 loc) 1.38 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 = (0, helpers_1.mathMLElementToLaTeXConverter)(children[0]).convert(); var sub = (0, helpers_1.mathMLElementToLaTeXConverter)(children[1]).convert(); var sup = (0, helpers_1.mathMLElementToLaTeXConverter)(children[2]).convert(); var wrappedSub = new helpers_1.BracketWrapper().wrap(sub); var wrappedSup = new helpers_1.BracketWrapper().wrap(sup); return "".concat(this._wrapInParenthesisIfThereIsSpace(base), "_").concat(wrappedSub, "^").concat(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;