UNPKG

az-mathml-to-latex

Version:

A JavaScript tool to convert mathml string to LaTeX string

51 lines (50 loc) 1.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MText = void 0; var MText = /** @class */ (function () { function MText(mathElement) { this._mathmlElement = mathElement; } MText.prototype.convert = function () { var _a = this._mathmlElement, attributes = _a.attributes, value = _a.value; return new TextCommand(attributes.mathvariant).apply(value); }; return MText; }()); exports.MText = MText; var TextCommand = /** @class */ (function () { function TextCommand(mathvariant) { this._mathvariant = mathvariant || 'normal'; } TextCommand.prototype.apply = function (value) { return this._commands.reduce(function (acc, command, index) { if (index === 0) return command + "{" + value + "}"; return command + "{" + acc + "}"; }, ''); }; Object.defineProperty(TextCommand.prototype, "_commands", { get: function () { switch (this._mathvariant) { case 'bold': return ['\\textbf']; case 'italic': return ['\\textit']; case 'bold-italic': return ['\\textit', '\\textbf']; case 'double-struck': return ['\\mathbb']; case 'monospace': return ['\\mathtt']; case 'bold-fraktur': case 'fraktur': return ['\\mathfrak']; default: return ['\\text']; } }, enumerable: false, configurable: true }); return TextCommand; }());