Inline formatting and colors

Apply emphasis, underline, strike, scripts, code, and alpha-composited colors.

Compare input and output

Compare the actual HTML/MathML input in your browser with the generated DOCX exported to PDF by LibreOffice. Open the DOCX in Word to inspect editable equations.

Browser · HTML / MathML

Open HTML preview

LibreOffice · PDF

Open PDF

For Markdown and LaTeX examples, the browser shows the generated HTML or MathML. Browser MathML support, Word styles, fonts and page layout can produce different results.

The PDF panel shows page images. Open the original PDF to zoom, search or select text, or download the DOCX to edit it.

Run

Extract the example bundle, install the example dependencies, and run this command from the folder containing examples/:

python -m examples.04_inline_formatting

Generated DOCX

Reference PDF

Complete source

"""04 inline formatting example."""

from mathml2docx import convert

from .support import save

document = convert("""<h1>Inline formatting</h1><p><b>Bold</b> <i>italic</i> <u>underline</u>
<del>removed</del> H<sub>2</sub>O x<sup>2</sup> <code>code()</code></p>
<p style="font-family:DejaVu Sans;font-size:14pt;color:navy">Named color and font</p>
<p style="background-color:blue"><span style="background-color:rgba(255,0,0,.5)">Purple blend</span></p>
<pre>first\tsecond\n  indented code</pre>""")
save(document, "04_inline_formatting.docx")