wordpaste → OMML to LaTeX
Microsoft Word does not store equations as pictures or as LaTeX. It stores them as
OMML — Office Math Markup Language — both inside a .docx
(in word/document.xml) and on the clipboard when you copy. This page converts
that OMML to LaTeX, in your browser, with no upload and no server.
Paste an <m:oMath> fragment — straight out of a .docx, or
from the HTML Word puts on the clipboard.
LaTeX appears here.
npm i wordpaste
import { ommlToLatex } from 'wordpaste';
const latex = ommlToLatex('<m:oMath>…</m:oMath>');
// '\\frac{a}{b}'
One function, string in and string out. It returns an empty string when the fragment cannot be parsed, so it never throws at you mid-paste.
transformPastedHTML instead — it cleans the whole
clipboard payload and converts the equations as part of that.
| OMML | Meaning | LaTeX |
|---|---|---|
m:f | fraction — bar, noBar, lin, skw | \frac, \binom, a/b |
m:rad | root, with or without a degree | \sqrt, \sqrt[n] |
m:sSub m:sSup m:sSubSup | sub- and superscripts | _{} ^{} |
m:sPre | pre-sub/superscript, as in an isotope | {}_{6}^{14}{C} |
m:nary | ∑ ∫ ∏ with limits | \sum_{}^{} |
m:d | delimiters, including ‖ ⌊ ⌈ ⟨ and empty sides | \left\lfloor … \right. |
m:acc | accents — the character decides which | \vec \bar \dot \hat … |
m:bar | rule above or below | \overline \underline |
m:m | matrix | \begin{matrix} |
m:eqArr | multi-line equation array | \begin{aligned} |
m:func m:limLow m:limUpp | named functions and limits | \lim_{} |
m:nor | a run marked upright — units, words | \text{} |
Unicode maths glyphs Word emits as plain runs (× ÷ ≥ ∞ ∆ π θ …) are mapped to their LaTeX commands, because KaTeX will not read several of them raw.
DOMParser. On
the server, give it one from jsdom first — there is a snippet in the
README.
transformPastedHTML handles that case, this function does not.
m:groupChr, m:borderBox, m:phant) are descended
into rather than translated, so their contents survive but their decoration does not.
Word puts an equation on the clipboard twice: once as a rasterised screenshot, and once as
the real OMML. Almost every editor takes the screenshot, so the maths is never editable
again. Reading the OMML instead is the whole point of
wordpaste, and
ommlToLatex is that part on its own, for when you are working with
.docx files rather than a paste.