UNPKG

@qtikit/mathml-to-latex

Version:

A JavaScript tool to convert mathml string to LaTeX string

34 lines (33 loc) 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MTable = void 0; var helpers_1 = require("../../../helpers"); var MTable = /** @class */ (function () { function MTable(mathElement) { this._mathmlElement = mathElement; this._addFlagRecursiveIfName(this._mathmlElement.children, 'mtable', 'innerTable'); } MTable.prototype.convert = function () { var tableContent = this._mathmlElement.children .map(function (child) { return (0, helpers_1.mathMLElementToLaTeXConverter)(child); }) .map(function (converter) { return converter.convert(); }) .join(' \\\\\n'); return this._hasFlag('innerTable') ? this._wrap(tableContent) : tableContent; }; MTable.prototype._wrap = function (latex) { return "\\begin{matrix}".concat(latex, "\\end{matrix}"); }; MTable.prototype._addFlagRecursiveIfName = function (mathmlElements, name, flag) { var _this = this; mathmlElements.forEach(function (mathmlElement) { if (mathmlElement.name === name) mathmlElement.attributes[flag] = flag; _this._addFlagRecursiveIfName(mathmlElement.children, name, flag); }); }; MTable.prototype._hasFlag = function (flag) { return !!this._mathmlElement.attributes[flag]; }; return MTable; }()); exports.MTable = MTable;