HTML and equations, ready for Word

Build Word documents from Python strings, files and document templates. mathml2docx converts supported HTML and MathML into formatted text and editable Word equations.

Start with a document

Install the published package from PyPI:

python -m pip install mathml2docx
from mathml2docx import convert

convert('<h1>Lesson notes</h1><p>The value <math><mi>x</mi></math> is editable.</p>',
        'lesson.docx')

Install the package and run this example with the getting started guide. Microsoft Office is not required for conversion.

Choose your workflow

Your input Where to start
HTML with text, tables or images Getting started and formatting recipes
MathML or LaTeX equations Equation layout and input handling
An existing Word template Markers, bookmarks and docxtpl
A scientific report or worksheet Research report and template workbook
Chemistry or nonstandard mathematics Chemical notation and fallback rendering
Code using mathml2docx 0.x Migration guide

Understand the output

Equations use Word's native OMML format, so supported formulas remain editable. HTML and CSS support is selective; browser layouts, arbitrary MathML notations and LaTeX packages are not all reproduced. Use explicit recovery for unsupported input and review the application compatibility guide for fonts and LibreOffice.

Browse all examples for complete Python code, DOCX downloads and PDF previews, or consult the API reference for individual options.