Converting LaTeX, MathML, or OMML strings to math objects using docx.js
npm install @seewo-doc/docx-math-converter``js
import { convertMathMl2Math } from 'docx-math-converter';
const mathObj = convertMathMl2Math(
);`
`js
import { convertOmml2Math } from 'docx-math-converter';
const mathObj = convertOmml2Math(
);`
`js
import { mathJaxReady, convertLatex2Math } from 'docx-math-converter';
await mathJaxReady();
const mathObj = convertLatex2Math('(a\\pm b)^2=a^2\\pm2ab+b^2');
`
NodeJS version
``
"node": ">=16.17.0"
Installing docx dependence require:
``
"docx": "^8.5.0"
`js
const doc = new Document({
sections: [
{
properties: {},
children: [
new Paragraph({
children: [
mathObj, // include mathObj
],
}),
],
},
],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});
``