Skip to main content

Convert MathML to OMML (Office Math Markup Language) in pure Python

Project description

math_ml2omml

A pure Python library to convert MathML strings into OMML (Office Math Markup Language).

This is a modern, patched version of the original mathml2omml library, containing key bug fixes and enhancements developed for the w2w (Word-to-Word Math Compiler) project to ensure 100% parity with Microsoft Word's professional equation layouts.

Key Enhancements in this Patched Version

  • Accent and Group Character Rendering: Fixed tag mismatches on <m:groupChr> inside MUnder and MOver classes. This ensures mathematical accents (like hats, tildes, dots) and underscript/overscript groupings compile and render correctly in Microsoft Word.
  • Improved Alignment and Layout Compatibility: Programmatic mapping fixes to match standard Office OpenXML (OOXML) math specifications.

Installation

You can install it directly from this package directory:

pip install .

Or for development (editable mode):

pip install -e .

Usage

import math_ml2omml

mathml = '<math><mi>x</mi><mo>+</mo><mi>y</mi></math>'
omml = math_ml2omml.convert(mathml)
print(omml)

Custom Entities

If your MathML contains custom entities, pass them as a dictionary:

import html.entities
mathml = '<math><msubsup><mo>&int;</mo><mn>1</mn><mi>x</mi></msubsup></math>'
omml = math_ml2omml.convert(mathml, html.entities.name2codepoint)

Running Tests

To verify the installation and run the suite of unit tests, execute the following command in the project root:

python -m unittest discover -s tests

Author

Patched and maintained by Robert Danaraj (salorajan@gmail.com).

Acknowledgements

Special thanks and deepest gratitude to George Kerscher (IMLS Profile), Chief Innovations Officer of the DAISY Consortium and President of the International Digital Publishing Forum. As a pioneering advocate for digital document accessibility (recognized as a White House Champion of Change), his invaluable discussion, guidance, and inspiration motivated the design, development, and deployment of this project.

We also thank the contributors of the daisy-math-a11y project for inspiring our work.

Keystroke Complexity Score (KCS)

This library includes a utility calculate_kcs() to compute the keyboard entry complexity cost of inputting mathematical equations into Microsoft Word's Equation Editor GUI. It is based on the Keystroke-Level Model (KLM) (Card, Moran, and Newell, 1980), adapted specifically for the interactive auto-build behaviors of Word's UnicodeMath input syntax:

  • Raw Keystrokes ($K$): Character count of the linear notation.
  • Cognitive Penalties ($C_i$): Additional weight for Shift keys (+1.0) and backslash escape sequences (+1.5).
  • Auto-Build Spacebars ($C_{spacebar}$): Weight for spacebar triggers required to compile structures like fractions, scripts, roots, and matrices (+2.0).
  • Fragility Penalty ($F$): Additional penalties (+10.0) for structures prone to user input errors without proper grouping.

Citations

  • Keystroke-Level Model (KLM): Card, S. K., Moran, T. P., and Newell, A. (1980). The Keystroke-Level Model for User Performance Time with Interactive Systems. Communications of the ACM, 23(7), 396–410.
  • UnicodeMath / Linear Math: Murray Sargent III. (2010). Unicode Sincerely, Math (Unicode Technical Note #28). Microsoft Corporation. UTN #28 Specification

License

MIT License. See LICENSE for details. Portions copyright (c) 2026 Daisy Project Contributors.

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

mathml_to_omml-1.0.3.tar.gz (146.5 kB view details)

Uploaded Source

Built Distribution

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

mathml_to_omml-1.0.3-py3-none-any.whl (32.6 kB view details)

Uploaded Python 3

File details

Details for the file mathml_to_omml-1.0.3.tar.gz.

File metadata

  • Download URL: mathml_to_omml-1.0.3.tar.gz
  • Upload date:
  • Size: 146.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for mathml_to_omml-1.0.3.tar.gz
Algorithm Hash digest
SHA256 cf6e10acb6ad6d9ea46f2a5432e7adb4a9fc1dc78fec79425eba4bcb93eab7ea
MD5 a70468bab56c046af2d4932e02a5da33
BLAKE2b-256 2bc58ffb6cf61713204407685b0fbdd0cd6a1482002eb9a084ab20699d5b2337

See more details on using hashes here.

File details

Details for the file mathml_to_omml-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: mathml_to_omml-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 32.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for mathml_to_omml-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9c19d1316fd48ea2c9d0a2f86e8fbdc563011ed34cb06fcd5487abc3acf40dea
MD5 138c4c9a08844da15e25525689a6d678
BLAKE2b-256 fdd893593d72e9dd6f0bfb14cfe6118cdca2321dfa8e0116a8ae9d0a8ebf3003

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