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.2.tar.gz (146.4 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.2-py3-none-any.whl (32.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mathml_to_omml-1.0.2.tar.gz
  • Upload date:
  • Size: 146.4 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.2.tar.gz
Algorithm Hash digest
SHA256 bdf3e5de18dd098f2623a0ee74fd49fae0b92174c5f037bfa37e74427206a7a4
MD5 9f148db413a7834f58fb743a4ab53f6a
BLAKE2b-256 ea4870df7042a9eb7d5678609256427eb4bbaa7214de90e937e76f317ee6ba09

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mathml_to_omml-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 851609f880a6b051d6ea8273b49529cf48b435c5497adac31b49e0dac691e472
MD5 1b328b9ede580215d64aab4de9a03c17
BLAKE2b-256 7cd0ca8cbf4dc1840f66be0e115537ed91dd39e7859789cc12775fb7015ba86f

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