Skip to main content

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 }}$

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

omml2latex-0.1.0.tar.gz (34.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

omml2latex-0.1.0-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file omml2latex-0.1.0.tar.gz.

File metadata

  • Download URL: omml2latex-0.1.0.tar.gz
  • Upload date:
  • Size: 34.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for omml2latex-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ccdfae7b337beeef660b4ce90944f99a676d3db4ba1a4a050fc9d297af3f9fb1
MD5 506b8a650c3f8513d25ce666ed16d4cb
BLAKE2b-256 d338f80a393859b7ea9f86d1f87400fca056764a748d6b1f1abbe4bde23b5384

See more details on using hashes here.

File details

Details for the file omml2latex-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: omml2latex-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 30.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for omml2latex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00bd0368d8ad8500967b3b532875aa54c42e596a1b0914e1ca3a154d216e29e4
MD5 979964bbf47b84721c1dc816d1784e72
BLAKE2b-256 cb122884a9458fcf66e651924504760f9b2b90e85cc2a714faeb079acbe60148

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page