{"id":13710,"library":"omml2mathml","title":"OMML to MathML Converter","description":"omml2mathml is a utility designed to convert Microsoft Office Math Markup Language (OMML) XML structures into standard MathML. The current stable version is 1.3.0, released in March 2021, suggesting a maintenance release cadence. This package serves as a direct port of Microsoft's `omml2mathml.xsl` XSLT stylesheet, but crucially, it operates without requiring an XSLT processor, which addresses common issues and crashes associated with such processors. It also incorporates fixes for several bugs found in the original Microsoft XSLT. The API is synchronous, accepting an `m:oMath` or `m:oMathPara` DOM element as input and returning a `math` element as an HTML DOM object, leveraging the `get-dom` module to ensure compatibility across browser environments (using native DOM) and Node.js (using `jsdom`). This removes the need for specific DOM implementations, making it flexible for various JavaScript environments.","status":"maintenance","version":"1.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/scienceai/omml2mathml","tags":["javascript","OMML","Office","Math","MathML"],"install":[{"cmd":"npm install omml2mathml","lang":"bash","label":"npm"},{"cmd":"yarn add omml2mathml","lang":"bash","label":"yarn"},{"cmd":"pnpm add omml2mathml","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used internally to provide a consistent DOM API across browser and Node.js environments; handles underlying DOM implementation like jsdom for Node.js.","package":"get-dom","optional":false}],"imports":[{"note":"The library exports a default function. Incorrectly using named imports will result in an undefined symbol.","wrong":"import { omml2mathml } from 'omml2mathml';","symbol":"omml2mathml","correct":"import omml2mathml from 'omml2mathml';"},{"note":"For CommonJS, use direct require for the default export. Destructuring will fail as it's not a named export.","wrong":"const { omml2mathml } = require('omml2mathml');","symbol":"omml2mathml","correct":"const omml2mathml = require('omml2mathml');"}],"quickstart":{"code":"import { DOMParser } from 'xmldom';\nimport omml2mathml from 'omml2mathml';\n\nconst parser = new DOMParser();\n\n// Example OMML input (a simple equation)\n// This OMML represents 'x_a'. Real OMML can be significantly more complex.\nconst ommlString = `\n<m:oMath xmlns:m=\"http://schemas.microsoft.com/office/2006/math\">\n  <m:r>\n    <m:t>x</m:t>\n  </m:r>\n  <m:sSub>\n    <m:e>\n      <m:r>\n        <m:t>a</m:t>\n      </m:r>\n    </m:e>\n    <m:sub>\n      <m:r>\n        <m:t>i</m:t>\n      </m:r>\n    </m:sub>\n  </m:sSub>\n</m:oMath>\n`;\n\nconst oMathDocument = parser.parseFromString(ommlString, 'application/xml');\nconst oMathElement = oMathDocument.documentElement; // This should be the <m:oMath> element\n\nif (oMathElement && (oMathElement.nodeName === 'm:oMath' || oMathElement.nodeName === 'm:oMathPara')) {\n  const mathmlElement = omml2mathml(oMathElement);\n  console.log('Converted MathML:');\n  // In a browser, you would append mathmlElement to the DOM\n  // In Node.js, you might serialize it for output or further processing\n  console.log(mathmlElement.outerHTML || new (require('xmldom').XMLSerializer)().serializeToString(mathmlElement));\n} else {\n  console.error(\"Could not find a valid m:oMath or m:oMathPara element in the input.\");\n}","lang":"javascript","description":"This quickstart demonstrates how to parse an OMML string using xmldom and convert the resulting DOM element into a MathML DOM element using omml2mathml, logging the output."},"warnings":[{"fix":"Use a DOM parser (e.g., `new DOMParser().parseFromString(ommlString, 'application/xml')` for `xmldom`) to get a DOM element before passing it to `omml2mathml`.","message":"The input to `omml2mathml` must be a DOM element (specifically an `m:oMath` or `m:oMathPara` element), not a raw XML string. You'll need a DOM parser (like `xmldom` in Node.js) to convert strings to elements first.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For performance-critical applications, consider offloading conversions to a Web Worker (in browser) or a separate child process (in Node.js) to avoid blocking the main thread.","message":"The conversion process is synchronous. For very large or numerous OMML documents, this can block the event loop in Node.js or the UI thread in browsers, potentially leading to performance issues or unresponsiveness.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Install a suitable XML DOM parser like `xmldom` (`npm install xmldom`) and use it to create DOM elements from your OMML strings before passing them to `omml2mathml`.","message":"While the library abstracts DOM implementation via `get-dom`, ensure that the environment has a compatible DOM parser if you are working with OMML strings. For Node.js, `xmldom` is a common choice for parsing XML into a DOM-like structure.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.3.0':28 '2021':32 'accept':87 'across':117 'address':61 'also':71 'api':84 'associ':66 'browser':118 'bug':76 'cadenc':37 'common':62 'compat':116 'convert':4,11 'crash':65 'crucial':52 'current':24 'design':9 'direct':43 'dom':94,106,112,122,133 'element':95,102 'ensur':115 'environ':119,141 'fix':73 'flexibl':137 'found':77 'get':111 'get-dom':110 'html':105 'implement':134 'incorpor':72 'input':97 'issu':63 'javascript':140,142 'jsdom':126 'languag':16 'leverag':108 'm':89,92 'mainten':35 'make':135 'march':31 'markup':15 'math':14,101,145 'mathml':3,22,146 'microsoft':12,46,81 'modul':113 'nativ':121 'need':130 'node.js':124 'object':107 'offic':13,144 'omath':90 'omathpara':93 'omml':1,17,143 'omml2mathml':5 'omml2mathml.xsl':48 'oper':54 'origin':80 'packag':39 'port':44 'processor':59,69 'releas':29,36 'remov':128 'requir':56 'return':99 'serv':40 'sever':75 'specif':132 'stabl':25 'standard':21 'structur':19 'stylesheet':50 'suggest':33 'synchron':86 'use':120,125 'util':8 'various':139 'version':26 'without':55 'xml':18 'xslt':49,58,82","created_at":"2026-04-20T01:55:54.935708+00:00","updated_at":"2026-04-20T01:55:54.935708+00:00","problems":[{"fix":"For ESM, use `import omml2mathml from 'omml2mathml';`. For CommonJS, use `const omml2mathml = require('omml2mathml');`.","cause":"Attempting to use `omml2mathml` as a named export (`import { omml2mathml } from 'omml2mathml';`) when it is a default export, or incorrect CommonJS require pattern.","error":"TypeError: omml2mathml is not a function"},{"fix":"Ensure the input is an actual `m:oMath` or `m:oMathPara` DOM element. Parse XML strings into DOM elements using a library like `xmldom` first.","cause":"This error can occur if the input passed to `omml2mathml` is not a valid DOM element or an object that mimics basic DOM operations, but rather a string or null/undefined.","error":"Uncaught TypeError: omml2mathml(...) is not a function or is undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/scienceai/omml2mathml","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/omml2mathml","openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}