wordpaste → OMML to LaTeX

Convert Word's OMML equations 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.

MIT zero dependencies 3.6 kB gzipped runs in the browser

Try it

Paste an <m:oMath> fragment — straight out of a .docx, or from the HTML Word puts on the clipboard.

OMML in
LaTeX out
LaTeX appears here.
Rendered (KaTeX)
Nothing to render yet.

Using it in code

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.

If what you actually have is a paste from Word rather than a bare OMML fragment, use transformPastedHTML instead — it cleans the whole clipboard payload and converts the equations as part of that.

What it converts

OMMLMeaningLaTeX
m:ffraction — bar, noBar, lin, skw\frac, \binom, a/b
m:radroot, with or without a degree\sqrt, \sqrt[n]
m:sSub m:sSup m:sSubSupsub- and superscripts_{} ^{}
m:sPrepre-sub/superscript, as in an isotope{}_{6}^{14}{C}
m:nary∑ ∫ ∏ with limits\sum_{}^{}
m:ddelimiters, including ‖ ⌊ ⌈ ⟨ and empty sides\left\lfloor … \right.
m:accaccents — the character decides which\vec \bar \dot \hat …
m:barrule above or below\overline \underline
m:mmatrix\begin{matrix}
m:eqArrmulti-line equation array\begin{aligned}
m:func m:limLow m:limUppnamed functions and limits\lim_{}
m:nora 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.

What it does not do

Why this exists

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.