Tools for generating MathType-compatible equation objects and DOCX equation layouts from MathML.
Project description
docx-equation
docx-equation builds DOCX equation content from MathML. It can export Word OMML equations or MathType-compatible OLE objects and uses shared layout helpers for numbered display equations.
Features
- MathML parsing into a shared equation AST.
- MathML to Word OMML conversion.
- MathML to MathType MTEF and
Equation.DSMT4OLE objects. - Optional
Equation.DSMT6OLE generation. - DOCX placeholder replacement for OMML or MathType output.
mc:AlternateContentMathType embedding with OMML fallback.- PNG-preview MathType embedding.
- Shared tabbed display-equation numbering with centered formulas and right-aligned labels.
- Configurable export options for target format, fonts, font sizes, MathType version, preview sizing, and numbering.
Install
python3 -m pip install docx-equation
For local development:
python3 -m venv .venv
. .venv/bin/activate
python3 -m pip install -e ".[dev]"
Package Layout
docx_equation.shared MathML parser, LaTeX subset parser, models, numbering helpers
docx_equation.omml MathML to OMML conversion and DOCX embedding
docx_equation.mathtype MTEF/OLE generation, preview rendering, DOCX embedding
docx_equation.api Public routing API for selected export targets
docx_equation.cli Command-line interface
Python API
Create OMML or MathType output from the same MathML placeholders:
from docx_equation import (
EquationSpec,
EquationStyle,
ExportOptions,
MathTypeOptions,
NumberingOptions,
OmmlOptions,
embed_mathml_placeholders,
)
equations = [
EquationSpec(
placeholder="{{DOCX_EQ_001}}",
mathml="<math xmlns='http://www.w3.org/1998/Math/MathML'><mi>x</mi></math>",
display=True,
number=1,
)
]
common = {
"style": EquationStyle(
font_family="Times New Roman",
east_asia_font="SimSun",
font_size_pt=10.5,
number_font_size_pt=10.5,
),
"numbering": NumberingOptions(chapter=4, sequence_name="Eq"),
}
embed_mathml_placeholders(
"input.docx",
"output_omml.docx",
equations,
ExportOptions(target="omml", omml=OmmlOptions(font_family="Times New Roman"), **common),
)
embed_mathml_placeholders(
"input.docx",
"output_mathtype.docx",
equations,
ExportOptions(
target="mathtype",
mathtype=MathTypeOptions(embed_mode="alternate-content", mathtype_version="DSMT4"),
**common,
),
)
Build standalone equation documents:
from docx_equation import ExportOptions, NumberingOptions, build_equation_docx
mathml_items = [
"<math xmlns='http://www.w3.org/1998/Math/MathML'><mfrac><mi>a</mi><mi>b</mi></mfrac></math>"
]
build_equation_docx(
mathml_items,
"equations.docx",
ExportOptions(target="mathtype", numbering=NumberingOptions(chapter=1)),
)
Generate raw objects:
from docx_equation import mathml_to_mathtype_ole, mathml_to_omml
mathml = "<math xmlns='http://www.w3.org/1998/Math/MathML'><mi>x</mi></math>"
ole_bytes = mathml_to_mathtype_ole(mathml)
omml_element = mathml_to_omml(mathml)
Command Line
Generate MTEF, OLE, or OMML artifacts:
docx-equation mathml equation.mml --mtef equation.mtef --ole oleObject1.bin --omml equation.omml
Build a DOCX from MathML files:
docx-equation demo equation_001.mml equation_002.mml -o equations.docx --target mathtype --chapter 4
Convert a DOCX:
docx-equation convert input.docx -o output.docx --target mathtype --embed-mode alternate-content
Inspect a DOCX:
docx-equation inspect output.docx
Build
python3 -m pip install -e ".[dev]"
python3 -m pytest
python3 -m build
python3 -m twine check dist/*
CI
GitHub Actions runs pytest, python -m build, and twine check dist/* on pushes and pull requests. PyPI publishing uses Trusted Publishing with the pypi GitHub environment. The publish job runs after CI on v* tag pushes, and it can also be started with workflow_dispatch when publish is set to true.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file docx_equation-0.3.0.tar.gz.
File metadata
- Download URL: docx_equation-0.3.0.tar.gz
- Upload date:
- Size: 32.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
673a4ff71d8b5b1b036ef24d73cb287b0a051226eedd923e4e8ead0033eff9b4
|
|
| MD5 |
5dfb68ff1c903c00e43ca732318a2f37
|
|
| BLAKE2b-256 |
46f70454b4f096271a32f31887e61a5cdabaea874e1cf37e85db880c02945ba0
|
Provenance
The following attestation bundles were made for docx_equation-0.3.0.tar.gz:
Publisher:
ci.yml on npofsi/docx-equation
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docx_equation-0.3.0.tar.gz -
Subject digest:
673a4ff71d8b5b1b036ef24d73cb287b0a051226eedd923e4e8ead0033eff9b4 - Sigstore transparency entry: 1803647645
- Sigstore integration time:
-
Permalink:
npofsi/docx-equation@bce70e2f0d4c4ed88a1e3799687382a58986c790 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/npofsi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@bce70e2f0d4c4ed88a1e3799687382a58986c790 -
Trigger Event:
push
-
Statement type:
File details
Details for the file docx_equation-0.3.0-py3-none-any.whl.
File metadata
- Download URL: docx_equation-0.3.0-py3-none-any.whl
- Upload date:
- Size: 38.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c0af5c0a4f9f33edee77bfae0416b54ac55f123a576e1c051de6ed44e8f4b45
|
|
| MD5 |
1e1ad8c0fcb13ff75970c8fd307171a2
|
|
| BLAKE2b-256 |
a81bf1a0ae9fa65395b24b4160ca135b355c7b047cbb6a489810a43e0e97bda0
|
Provenance
The following attestation bundles were made for docx_equation-0.3.0-py3-none-any.whl:
Publisher:
ci.yml on npofsi/docx-equation
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docx_equation-0.3.0-py3-none-any.whl -
Subject digest:
9c0af5c0a4f9f33edee77bfae0416b54ac55f123a576e1c051de6ed44e8f4b45 - Sigstore transparency entry: 1803647855
- Sigstore integration time:
-
Permalink:
npofsi/docx-equation@bce70e2f0d4c4ed88a1e3799687382a58986c790 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/npofsi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@bce70e2f0d4c4ed88a1e3799687382a58986c790 -
Trigger Event:
push
-
Statement type: