Skip to main content

mdtex2html

python3-library to convert Markdown with included LaTeX-Formulas to HTML with MathML

What is mdtex2html

mdtex2html is a library to convert (Github-flavored) Markdown-Code with included LaTex-formulas to HTML-Source. The formulas are converted to MathML.

An inline-formula can either start and end with $ or it can start with \( and end with \), according to valid LaTeX-Code. Block-formulas either start and end with $$ or start with \[ and end with \].

An example that mdtex2html will convert:

# Example-Title

TeX-Formula: $\sqrt2=x^2 \Rightarrow x=\sqrt{\sqrt{2}}$

- This
- is
    - a List with `inline-Code`

How to use mdtex2html

install it, i.e. using pip:

python3 -m pip install mdtex2html

then in python import in your code with

import mdtex2html

and convert your mdTeX with something like

mdtex2html.convert('- Hello ${\sqrt{World}}^2$!')

passing any mdTeX-Code to mdtex2html.convert().

Extra

You may want to (but don't need to) include this css-snippet on your page to hide error message texts, only showing on mouse-over:

.tooltip .tooltiptext {
    display: none;
}
.tooltip:hover .tooltiptext {
    display: inline;
    border-radius: 0.3em;
    background-color: #777;
    position: fixed;
}

Markdown-Extensions

Starting with v1.1 you can use python-markdown-extensions for i.e. tables, definition-lists, html-attributes and much more by passing a list of the extension(s) to be used to the convert-command as described in the python-markdown documentation.

For example mdtex2html.convert('Hello green\n{: style="color:green" }', extensions=['attr_list']) will make use of the extension attr_list.

Dependencies

This depends on:

The dependencies will be installed when installing using pip.

Limitations

The Firefox browser will display the result smoothly, as well as Safari (according to user reports).

Just be aware that the Chromium-engine (Browsers: Chrome, Edge, ...) still is not able to render MathML properly, but rumors say that in 2020 work has started again to make that happen, so maybe you want to check the status there. In 2023 MathML Core got finally supported by the Blink-Engine of Chrome (and therefore Edge etc.). So this works now in all mainstream-browsers.

Credits

Special thanks to Ronie Martinez for creating latex2html!

This library is just a few lines of code added to his work and to Python-Markdown.

Release files for mdtex2html 1.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mdtex2html 1.3.2
File Size Uploaded
mdtex2html-1.3.2.tar.gz 15.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mdtex2html 1.3.2
File Interpreter ABI Platform
mdtex2html-1.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 29.2 kB

Release files / mdtex2html-1.3.2.tar.gz

Download URL mdtex2html-1.3.2.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3b2bc613e62ffdce39a9627d60a244cbbbb732b4bfcc30ddae97a9dff7d18d6d
BLAKE2b-256 checksum
How to use checksums
9114459e52f51b90a5a8a8827aff6593ea88de76d1a3c1a83a41da04767e209d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / mdtex2html-1.3.2-py3-none-any.whl

Download URL mdtex2html-1.3.2-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9bf8985ba3f1641c62df3cb9d6bb7151031bd6018ee30ad8184749ba696c2f3d
BLAKE2b-256 checksum
How to use checksums
d7b13f39c658ce35880d4a1cc4c7854af604b905f46ae095ecb637fecbdf2d6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

1.3.2 This release

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.9.9

2 release files

0.9.8

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page