Metadata-Version: 2.4
Name: academic-mathtype-engine
Version: 1.0.0
Summary: Generate embedded MathType-compatible equation objects in Word documents from LaTeX
License-Expression: Apache-2.0
Project-URL: Repository, https://github.com/waterboyNick/academic-mathtype-engine
Project-URL: Documentation, https://github.com/waterboyNick/academic-mathtype-engine#readme
Project-URL: Issues, https://github.com/waterboyNick/academic-mathtype-engine/issues
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: LICENSE_STATUS.md
License-File: THIRD_PARTY_NOTICES.md
Requires-Dist: python-docx<2,>=1.2
Requires-Dist: lxml<7,>=6.1.1
Requires-Dist: Pillow<13,>=12.3
Requires-Dist: matplotlib<4,>=3.10.8
Provides-Extra: test
Requires-Dist: olefile<1,>=0.47; extra == "test"
Requires-Dist: tomli>=2; python_version < "3.11" and extra == "test"
Dynamic: license-file

# Academic MathType Engine

Generate a Word equation collection from LaTeX on Linux, macOS or Windows. Each equation has its own embedded `Equation.DSMT4` OLE object and associated PNG preview. The independent backend constructs both parts locally. Word and MathType are required on the editing workstation only.

**Version 1.0.0.** The maintainer checked the delivered 105-equation document in Windows Word and reported that it worked. For the same inputs, the release writer reproduces all 227 document parts byte for byte. The exact desktop builds and per-equation editing observations were not reported. [中文](README.zh-CN.md) · [Verification](VALIDATION_REPORT.md) · [Licensing](LICENSE_STATUS.md)

## Install and generate

Use Python 3.10 or newer. Install from PyPI in your virtual environment.

```sh
python -m pip install academic-mathtype-engine==1.0.0
academic-mathtype doctor
```

For a CLI example, save this UTF-8 array as `input.json`.

```json
[
  {"id":"eq1","label":"Quadratic fraction","latex":"\\frac{x_i^2+1}{y_0}"},
  {"id":"eq2","label":"Inline variable","latex":"x+1","inline":true}
]
```

```sh
academic-mathtype build input.json demo.docx
academic-mathtype validate demo.docx --expected 2
```

The equivalent Python program is self-contained.

```python
from academic_mathtype import build_docx, compile_latex, pack_ole, validate_docx

cases = [{"id": "q", "label": "Normalized response", "latex": r"\frac{x_i^2+1}{y_0}"},
         {"id": "r", "label": "Inline residual", "latex": "r=x-y", "inline": True}]
build_docx(cases, "equations.docx")
validate_docx("equations.docx", len(cases))
ole_bytes = pack_ole(compile_latex(cases[0]["latex"]))
```

The CLI accepts a UTF-8 JSON array with these same fields. Escape each LaTeX backslash as `\\` in JSON. IDs must be unique. Use `--title` and `--per-page` to lay out a collection. The CLI requires `--overwrite` to replace a file. The Python API validates the entire document before replacing the destination. Installed commands are also available through `python -m academic_mathtype`.

## Formula and preview support

The grammar covers Latin and selected Greek symbols, functions, scripts, fractions, square roots, accents, vector and font styles, fences, six matrix/cases environments, integrals, sums, products and lower limits. Use paired braces for compound operands, e.g. `\sum_{i=1}^{n}{a_i-b_i}`. Indexed roots, arbitrary macros and arbitrary TeX environments are outside this dialect. Limits include 700 tokens per expression, 12 × 12 per matrix and a bounded native body of 1 MiB.

Install TeX providing `latex`, `amsmath`, `amssymb` and `dvipng` for the full preview set. With these commands missing, Matplotlib mathtext can render simpler previews. An unavailable preview or unsupported expression aborts the build. Read the diagnostic for the equation ID. Run `doctor` to check the native round trip and whether the TeX commands are discoverable on PATH.

## Verification and contribution

The frozen tests verify eight files, 29 exact MTEF bodies and 100 historical OLE/native hashes. The independent corpus includes 105 accepted inputs and 10 rejection cases. The checklist can record separate editing observations for specific desktop builds. [Historical record](VALIDATION.md) · [Acceptance materials](validation/) · [Architecture](ARCHITECTURE.md)

```sh
python -m pip install ".[test]"
python -m unittest -v test_engine test_frozen test_document
python -m unittest discover -s tests -v
python -m unittest discover -s release -v
```

Submit changes on a branch with a minimal LaTeX input, its expected mathematical structure and a regression check. Keep private manuscripts, local profiles and third-party template binaries off the repository. Preserve the frozen manifest and tag. The package declares dependency ranges in `pyproject.toml`; `requirements.txt` records the historical reproduction versions. [Agent workflows](docs/SKILLS.md) · [Source provenance](SOURCE_PROVENANCE.md) · [Third-party notices](THIRD_PARTY_NOTICES.md) · [Publication gates](PYPI_RELEASE_READINESS.md)
