UNPKG

@qtikit/mathml-to-latex

Version:

A JavaScript tool to convert mathml string to LaTeX string

50 lines (49 loc) 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GenericUnderOver = void 0; var mathml_element_to_latex_converter_1 = require("../../../helpers/mathml-element-to-latex-converter"); var errors_1 = require("../../../errors"); var latex_accents_1 = require("../../../../syntax/latex-accents"); var GenericUnderOver = /** @class */ (function () { function GenericUnderOver(mathElement) { this._mathmlElement = mathElement; } GenericUnderOver.prototype.convert = function () { var _a = this._mathmlElement, name = _a.name, children = _a.children; var childrenLength = children.length; if (childrenLength !== 2) throw new errors_1.InvalidNumberOfChildrenError(name, 2, childrenLength); var content = (0, mathml_element_to_latex_converter_1.mathMLElementToLaTeXConverter)(children[0]).convert(); var accent = (0, mathml_element_to_latex_converter_1.mathMLElementToLaTeXConverter)(children[1]).convert(); return this._applyCommand(content, accent); }; GenericUnderOver.prototype._applyCommand = function (content, accent) { var type = this._mathmlElement.name.match(/under/) ? TagTypes.Under : TagTypes.Over; return new UnderOverSetter(type).apply(content, accent); }; return GenericUnderOver; }()); exports.GenericUnderOver = GenericUnderOver; var UnderOverSetter = /** @class */ (function () { function UnderOverSetter(type) { this._type = type; } UnderOverSetter.prototype.apply = function (content, accent) { return latex_accents_1.latexAccents.includes(accent) ? "".concat(accent, "{").concat(content, "}") : "".concat(this._defaultCommand, "{").concat(accent, "}{").concat(content, "}"); }; Object.defineProperty(UnderOverSetter.prototype, "_defaultCommand", { get: function () { if (this._type === TagTypes.Under) return '\\underset'; return '\\overset'; }, enumerable: false, configurable: true }); return UnderOverSetter; }()); var TagTypes; (function (TagTypes) { TagTypes[TagTypes["Under"] = 0] = "Under"; TagTypes[TagTypes["Over"] = 1] = "Over"; })(TagTypes || (TagTypes = {}));