UNPKG

@qtikit/mathml-to-latex

Version:

A JavaScript tool to convert mathml string to LaTeX string

30 lines (29 loc) 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MFrac = void 0; var errors_1 = require("../../../errors"); var helpers_1 = require("../../../helpers"); var MFrac = /** @class */ (function () { function MFrac(mathElement) { this._mathmlElement = mathElement; } MFrac.prototype.convert = function () { var _a = this._mathmlElement, children = _a.children, name = _a.name; var childrenLength = children.length; if (childrenLength !== 2) throw new errors_1.InvalidNumberOfChildrenError(name, 2, childrenLength); var num = (0, helpers_1.mathMLElementToLaTeXConverter)(children[0]).convert(); var den = (0, helpers_1.mathMLElementToLaTeXConverter)(children[1]).convert(); if (this._isBevelled()) return "".concat(this._wrapIfMoreThanOneChar(num), "/").concat(this._wrapIfMoreThanOneChar(den)); return "\\frac{".concat(num, "}{").concat(den, "}"); }; MFrac.prototype._wrapIfMoreThanOneChar = function (str) { return new helpers_1.ParenthesisWrapper().wrapIfMoreThanOneChar(str); }; MFrac.prototype._isBevelled = function () { return !!this._mathmlElement.attributes.bevelled; }; return MFrac; }()); exports.MFrac = MFrac;