mathml2docx
English · 한국어 · Documentation
Convert HTML and MathML into Word documents with Python. Create reports, worksheets and templates with editable equations, formatted text, tables and images. Microsoft Office is not required to generate a document.
Python 3.6+ · Optional LaTeX and Markdown inputs · MIT license
Installation
Install the published package from PyPI:
python -m pip install mathml2docx
# With optional LaTeX and Markdown support:
python -m pip install "mathml2docx[latex,markdown]"
Python 3.6.2+ is required for the optional LaTeX frontend. Library users do not need uv. Pin the package version in your project's requirements or lockfile for reproducible installations. See development setup to work on the library's source.
Update an existing installation with python -m pip install --upgrade mathml2docx.
Users upgrading from 0.x should read the migration guide.
Your first Word document
from mathml2docx import convert
convert('''
<h1>Lesson notes</h1>
<p>The value <math><mfrac><mn>1</mn><mn>2</mn></mfrac></math> is one half.</p>
<math display="block"><msup><mi>x</mi><mn>2</mn></msup></math>
''', 'lesson.docx')
Open lesson.docx in Word to edit its text and equations. convert() also returns
a python-docx Document; omit the output path to continue editing it in Python.
What it supports
| Input or task | Features |
|---|---|
| HTML | Headings, paragraphs, links, nested lists and text formatting |
| Tables | Merged cells, nested tables and Word table styles |
| Images | Data URLs, configured local files and explicit application loaders |
| CSS | Supported selectors, fonts, colors, alignment and page breaks |
| MathML | Fractions, roots, scripts, limits, accents, matrices, selected enclosures and isotope scripts |
| LaTeX / Markdown | Optional frontends using latex2mathml and Python-Markdown |
| Templates | Add to an existing document or cell; replace markers and bookmarks |
The converter implements a documented subset of HTML, CSS and Presentation MathML. It does not reproduce a complete browser layout.
Equation layout and unsupported input
<math> is inline by default, following MathML. Use display="block" for a
separate display equation. To retain block behavior for input that omits display:
from mathml2docx import MathmlToDocx
parser = MathmlToDocx(default_math_display='block')
Unsupported mathematical structures raise UnsupportedMathMLError by default.
Applications handling mixed input can select unsupported_math='text' to preserve
the formula's XML visibly, provide mathml_fallback(source, error) returning text
or an image, or normalize input with mathml_preprocessor(source). Recovery emits
MathMLFallbackWarning; invalid XML still raises an error.
See equation handling
for supported notations and complete examples.
LaTeX, Markdown and command line
from mathml2docx import MathmlToDocx
parser = MathmlToDocx()
parser.parse_latex(r'\frac{1}{2} + x_1^2').save('equation.docx')
parser.parse_markdown('# Notes\n\n**Bold** and ~~removed~~ text.').save('notes.docx')
mathml2docx input.html output.docx
mathml2docx equation.tex equation.docx --format latex
mathml2docx input.html output.docx --default-math-display block --unsupported-math text
Use --force to replace an existing output file. HTML dollar delimiters are not
interpreted as LaTeX. Network images and stylesheets require explicit loaders.
Guides and examples
- Getting started · API and options · Recipes
- Runnable examples and DOCX downloads: formatting, templates, scientific reports, chemistry and fallback rendering.
- MathML fidelity example: inherited defaults, accents, equation styles, links and template replacement.
- Migration from 0.x · Compatibility and validation
- 한국어 문서
For headless PDF conversion with LibreOffice, install Writer and Math, plus
appropriate fonts. Writer-only installations can leave equations blank. The
rendering guide
includes installation and verification commands. Use math_target='libreoffice'
with an explicit fallback for known enclosure differences.
Contributing and license
Work from develop; see development and releases
for setup, tests and publishing. Changes are listed in CHANGELOG.md.
MIT, derived from html2docx. Dependencies retain their own licenses; see THIRD_PARTY_NOTICES.md. The 1.0 converter constructs OMML directly and includes no Office XSL. Historical 0.x distributions are covered separately in the provenance record.
Metadata
Release files for mathml2docx 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mathml2docx-1.0.1.tar.gz | 1.3 MB | With provenance | Details for mathml2docx-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mathml2docx-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for mathml2docx-1.0.1-py3-none-any.whl |
Total release size: 1.3 MB
Release files / mathml2docx-1.0.1.tar.gz
| Download URL | mathml2docx-1.0.1.tar.gz |
|---|---|
| Size | 1.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd2bfeda31b6dca51873bf059860e4252e5e8712d31d4fe30baebef5ee9037f5
|
|
BLAKE2b-256 checksum How to use checksums |
fba9e9278fb6935f7ba396c398b5e08be2ad73130ce5b6dde44bb8387d8dda45
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logRelease files / mathml2docx-1.0.1-py3-none-any.whl
| Download URL | mathml2docx-1.0.1-py3-none-any.whl |
|---|---|
| Size | 42.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a8dfd420c38f4f03b5f629d9615ea89306e65b43fd36c2d02e0f5db9dbc47983
|
|
BLAKE2b-256 checksum How to use checksums |
de2fa9403f4c99ba1fc64d6b9527ca93f8a754a5174bb2dd6f0375bcc103cb60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logSecurity for mathml2docx 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mathml2docx-1.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.