Metadata-Version: 2.4
Name: mathml_to_omml
Version: 1.0.3
Summary: Convert MathML to OMML (Office Math Markup Language) in pure Python
Home-page: https://github.com/salorajan/math_2omml
Author: amedama, w2w Contributors
Author-email: amedama <amedama@example.com>, w2w Contributors <contributors@w2w.org>
License-Expression: MIT
Project-URL: Homepage, https://github.com/salorajan/math_2omml
Project-URL: Repository, https://github.com/salorajan/math_2omml
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Text Processing :: Markup :: XML
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: latex2mathml
Requires-Dist: lxml
Requires-Dist: python-docx
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# 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:
```bash
pip install .
```

Or for development (editable mode):
```bash
pip install -e .
```

## Usage

```python
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:
```python
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:
```bash
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](https://www.imls.gov/about-us/national-museum-and-library-services-board/george-kerscher)), 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](https://github.com/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](https://www.unicode.org/notes/tn28/UTN28-PlainTextMath-v3.pdf)


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


