@qtikit/mathml-to-latex
Version:
A JavaScript tool to convert mathml string to LaTeX string
52 lines (51 loc) • 1.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MText = void 0;
var normalize_category_code_1 = require("../../../helpers/normalize-category-code");
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((0, normalize_category_code_1.normalizeCategoryCode)(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 "".concat(command, "{").concat(value, "}");
return "".concat(command, "{").concat(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;
}());