Registry / serialization / omml2mathml

omml2mathml

JSON →
library1.3.0jsnpmunverified

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.

npm install omml2mathml
INSTALL
IMPORT
SIG · OMML2MATHML
O
omml2mathml
serializationjavascriptv1.3.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

omml2mathml
import omml2mathml from 'omml2mathml';
import { omml2mathml } from 'omml2mathml';
The library exports a default function. Incorrectly using named imports will result in an undefined symbol.
omml2mathml
const omml2mathml = require('omml2mathml');
const { omml2mathml } = require('omml2mathml');
For CommonJS, use direct require for the default export. Destructuring will fail as it's not a named export.

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.

import { DOMParser } from 'xmldom'; import omml2mathml from 'omml2mathml'; const parser = new DOMParser(); // Example OMML input (a simple equation) // This OMML represents 'x_a'. Real OMML can be significantly more complex. const ommlString = ` <m:oMath xmlns:m="http://schemas.microsoft.com/office/2006/math"> <m:r> <m:t>x</m:t> </m:r> <m:sSub> <m:e> <m:r> <m:t>a</m:t> </m:r> </m:e> <m:sub> <m:r> <m:t>i</m:t> </m:r> </m:sub> </m:sSub> </m:oMath> `; const oMathDocument = parser.parseFromString(ommlString, 'application/xml'); const oMathElement = oMathDocument.documentElement; // This should be the <m:oMath> element if (oMathElement && (oMathElement.nodeName === 'm:oMath' || oMathElement.nodeName === 'm:oMathPara')) { const mathmlElement = omml2mathml(oMathElement); console.log('Converted MathML:'); // In a browser, you would append mathmlElement to the DOM // In Node.js, you might serialize it for output or further processing console.log(mathmlElement.outerHTML || new (require('xmldom').XMLSerializer)().serializeToString(mathmlElement)); } else { console.error("Could not find a valid m:oMath or m:oMathPara element in the input."); }
Debug
Known issues
gotchaThe 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.
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`.
affects: >=1.0.0
gotchaThe 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.
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.
affects: >=1.0.0
gotchaWhile 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.
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`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: omml2mathml is not a function
Attempting to use `omml2mathml` as a named export (`import { omml2mathml } from 'omml2mathml';`) when it is a default export, or incorrect CommonJS require pattern.
fix
For ESM, use `import omml2mathml from 'omml2mathml';`. For CommonJS, use `const omml2mathml = require('omml2mathml');`.
Uncaught TypeError: omml2mathml(...) is not a function or is undefined
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.
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.
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies
get-domrequiredUsed internally to provide a consistent DOM API across browser and Node.js environments; handles underlying DOM implementation like jsdom for Node.js.
Agent activity
9 hits · last 30 days
node
8
Perplexity
1
Resources
omml2mathml — npm install omml2mathml · libregistry