Convert OMML (Office Math Markup Language) elements into LaTeX.
Project description
omml2latex
Convert OMML (Office Math Markup Language) elements from MS Office documents into KaTeX-compatible LaTeX strings. No external dependencies.
Installation
pip install omml2latex
Quick Start
MS Office documents (.pptx, .docx) store math equations internally as
OMML XML elements. Pass an m:oMath element to convert_omml to get a
LaTeX string:
import xml.etree.ElementTree as ET
from omml2latex import convert_omml
xml_string = """
<m:oMath xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">
<m:r>
<m:rPr><m:scr m:val="double-struck"/><m:sty m:val="b"/></m:rPr>
<m:t>Rα∞</m:t>
</m:r>
</m:oMath>
"""
root = ET.fromstring(xml_string)
print(convert_omml(root))
# $\mathbf{\mathbb{R \alpha \infty }}$
CLI
Extract all equations from a .pptx or .docx file:
omml2latex input.pptx # print equations to stdout
omml2latex input.pptx -o output.txt # save to file
Handles AlternateContent wrappers and a14:m containers used by PowerPoint when equations are embedded in text frames.
API
convert_omml(node)
| Parameter | Type | Description |
|---|---|---|
node |
xml.etree.ElementTree.Element |
An m:oMath, m:oMathPara, or m:mathPr element |
Returns a KaTeX-compatible LaTeX string:
m:oMath→$...$(inline math)m:oMathPara→$$...$$(display math)m:mathPr→""(global math settings, no output)
Extracting Equations from a PPTX or DOCX File
OOXML files (.pptx, .docx) are ZIP archives containing XML files inside.
To extract all equations from a file, open it with zipfile and search for
m:oMath elements:
import zipfile
import xml.etree.ElementTree as ET
from omml2latex import convert_omml
MATH_NS = "http://schemas.openxmlformats.org/officeDocument/2006/math"
with zipfile.ZipFile("presentation.pptx") as zf:
for name in zf.namelist():
if name.startswith("ppt/slides/slide") and name.endswith(".xml"):
tree = ET.fromstring(zf.read(name))
for node in tree.iter(f"{{{MATH_NS}}}oMath"):
print(convert_omml(node))
For .docx files, replace ppt/slides/slide with word/document:
with zipfile.ZipFile("document.docx") as zf:
tree = ET.fromstring(zf.read("word/document.xml"))
for node in tree.iter(f"{{{MATH_NS}}}oMath"):
print(convert_omml(node))
Features
- ECMA-376 based: built from the official OMML schema definitions
- Recursive descent parser: handles nested structures (fractions, matrices, accents, large operators, etc.)
- Unicode math mapping: automatically maps Unicode Mathematical Alphabet characters (𝑓, 𝜋, 𝒜, …) to their LaTeX equivalents
License
Apache 2.0 — Copyright 2026 INSEONG LEE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file omml2latex-0.1.1.tar.gz.
File metadata
- Download URL: omml2latex-0.1.1.tar.gz
- Upload date:
- Size: 35.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eda9ff25c881f753357c325ab7a63ba33ad807f0ec8293fff39c8b370ff9084a
|
|
| MD5 |
b662548ed0d41cc9f6bc8d09f306f647
|
|
| BLAKE2b-256 |
4c9c4c6f8ec7ffdf3ee5dbb0d0d4d68233cbcd137f800e40e69d6e2e0da87692
|
File details
Details for the file omml2latex-0.1.1-py3-none-any.whl.
File metadata
- Download URL: omml2latex-0.1.1-py3-none-any.whl
- Upload date:
- Size: 32.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b24a13f4a14791662972d1b6716e5a1f9114891ccf1a96622f61dbfb1c300bd4
|
|
| MD5 |
fe8d62508c84ba5bbb4ea59ce64d1dc2
|
|
| BLAKE2b-256 |
aa66528fd921508c4a84c4d7f2cc6bf1ae45c96a387081d90e3a60d3e4a1a245
|