Metadata-Version: 2.4
Name: mathml_to_omml
Version: 1.1.0
Summary: Convert MathML/LaTeX to OMML (Word MathZone), MathCAT speech/braille, and accessible HTML5 in pure Python
Home-page: https://github.com/salorajan/mathml_to_omml
Author: salorajan, w2w Contributors
Author-email: salorajan <salorajan@gmail.com>, w2w Contributors <contributors@w2w.org>
License-Expression: MIT
Project-URL: Homepage, https://github.com/salorajan/mathml_to_omml
Project-URL: Repository, https://github.com/salorajan/mathml_to_omml
Project-URL: Documentation, https://github.com/salorajan/mathml_to_omml/blob/main/manual.md
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Education
Classifier: Programming Language :: Python :: 3
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: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Text Processing :: Markup :: XML
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: latex2mathml>=3.81.0
Requires-Dist: lxml>=5.0.0
Requires-Dist: python-docx>=1.0.0
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# mathml_to_omml (math_ml2omml)

**A pure Python library for Office Math Markup Language (OMML) conversion, MathCAT-powered accessible speech & Braille synthesis, and interactive HTML5 mathematical document publishing.**

[![PyPI version](https://img.shields.io/pypi/v/mathml_to_omml.svg)](https://pypi.org/project/mathml-to-omml/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)

---

## Overview

`mathml_to_omml` (module name `math_ml2omml`) bridges the gap between digital accessibility, web presentation, and desktop office publishing:

1. **Native Office OMML Engine**: Converts MathML 3.0, LaTeX, and UnicodeMath (linear math) into genuine Microsoft Word (`<m:oMath>` / `<m:oMathPara>`) MathZones for `.docx` documents.
2. **Accessible Spoken Math & Braille**: Integrates MathCAT (the official math accessibility engine inside NVDA) to produce context-aware spoken readings (ClearSpeak, SimpleSpeak, MathSpeak) and standardized tactile Nemeth and UEB Braille.
3. **Interactive HTML5 Math Drawers**: Compiles Markdown documents containing LaTeX/MathML into WCAG 2.2 AA compliant HTML5 pages featuring zero-dependency in-place keyboard tree navigation drawers (drill down into numerators, denominators, radicals, and matrices using arrow keys).
4. **Chemical Equation Support**: Built-in support for `\ce{...}` (mhchem) syntax, state of matter indicators, reaction arrows, and chemical element lookups.
5. **Keystroke Complexity Scoring (KCS)**: Benchmarks authoring efficiency based on the Keystroke-Level Model (KLM).

---

## Installation

Install from PyPI:
```bash
pip install mathml_to_omml
```

Or install from source in editable mode:
```bash
git clone https://github.com/salorajan/mathml_to_omml.git
cd mathml_to_omml
pip install -e .
```

---

## Python API Usage

### 1. MathML to OMML
```python
import math_ml2omml

mathml = '<math><mfrac><mi>a</mi><mi>b</mi></mfrac></math>'
omml = math_ml2omml.convert(mathml)
print(omml)
```

### 2. LaTeX to OMML
```python
import math_ml2omml

latex = r"\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}"
omml = math_ml2omml.latex_to_omml(latex, display=True)
print(omml)
```

### 3. Spoken Math Reading & Braille Synthesis
```python
import math_ml2omml

# Spoken reading in English
speech_en = math_ml2omml.speak(r"\frac{a}{b}")
print(speech_en)  # "fraction with numerator a over denominator b"

# Spoken reading in Spanish
speech_es = math_ml2omml.speak(r"\frac{a}{b}", language="es")
print(speech_es)  # "fracción con numerador a sobre denominador b"

# Tactile Braille (Nemeth / UEB)
braille = math_ml2omml.to_braille("x^2 + y^2 = z^2", braille_code="Nemeth")
print(braille)
```

### 4. Compile Markdown to Accessible HTML5
```python
import math_ml2omml

md_content = """# Quantum Mechanics
An iconic relationship is:
$$E = mc^2$$
And chemical reaction:
$$\\ce{2H2 + O2 -> 2H2O}$$
"""

html_page = math_ml2omml.compile_markdown_to_accessible_html(md_content, title="Quantum Paper")

# Or compile file directly
math_ml2omml.compile_file("input.md", "output.html")
```

### 5. Generate Microsoft Word (.docx) Documents
```python
import math_ml2omml

math_ml2omml.create_math_document("document.docx", md_content, title="Accessible Math Document")
```

---

## Command Line Interface (CLI)

The package provides the `math-ml2omml` CLI tool:

```bash
# Convert MathML to OMML
math-ml2omml convert "<math><mfrac><mi>x</mi><mi>y</mi></mfrac></math>"

# Convert LaTeX directly to OMML
math-ml2omml latex-omml "\frac{a}{b}"

# Compile Markdown to accessible HTML5 with in-place tree navigation
math-ml2omml compile-html paper.md -o paper.html

# Generate spoken math description
math-ml2omml speak "\sqrt{x^2 + 1}"

# Synthesize Braille
math-ml2omml braille "E=mc^2" --code Nemeth

# Transpile Chemistry and generate speech
math-ml2omml chem "\ce{2H2 + O2 -> 2H2O}"

# Inspect equation AST tree JSON
math-ml2omml inspect "\frac{a+b}{c}"

# Built-in help utility
math-ml2omml help
```

---

## Interactive Tree Navigation Shortcuts

When viewing compiled HTML5 documents, users can explore equations using keyboard navigation:
- **`🎯 Navigate In-Place`** / **Enter**: Open the in-place navigation drawer.
- **`↓` (Down Arrow)** / **Enter**: Drill down into sub-expressions (numerator, radicand, exponent).
- **`↑` (Up Arrow)** / **Esc**: Go up to parent expression.
- **`←` / `→` (Left / Right Arrows)**: Step through sibling terms.
- **`Backspace`**: Exit drawer.
- **`🔊 Speak`**: Listen to full spoken math reading.
- **`📋 Code & Details`**: Inspect MathML, LaTeX, and AST node properties.

---

## Running the Test Suite

Run the full pytest suite:
```bash
pytest tests -v
```

---

## 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 guidance and inspiration motivated the design and deployment of this project.

We also thank the contributors of **MathCAT** ([daisy/MathCAT](https://github.com/daisy/MathCAT)) and the DAISY Consortium for the open-source speech and braille engines.

---

## License

MIT License. See [LICENSE](LICENSE) for details.
