Python-Markdown Math is an extension for the Python-Markdown library that adds support for rendering mathematical formulas written in LaTeX-like syntax. It converts math expressions within Markdown into a format compatible with client-side JavaScript rendering libraries like MathJax. The current version is 0.9, released in April 2025, and it maintains a moderate release cadence based on its history.
pip install python-markdown-mathVerified import paths — ran on the pinned version, not inferred.
The quickstart demonstrates how to initialize the Python-Markdown parser with the `mdx_math` extension. It also shows how to enable the single dollar sign delimiter for inline math, which is disabled by default. The critical point is that the extension only generates MathJax-compatible HTML; actual visual rendering requires including the MathJax JavaScript library in your final HTML document.
Ensure your HTML output includes the MathJax library. For example: `<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js"></script>` along with its configuration.
Pass `extension_configs={'mdx_math': {'enable_dollar_delimiter': True}}` when initializing the Markdown parser: `markdown.Markdown(extensions=['mdx_math'], extension_configs={'mdx_math': {'enable_dollar_delimiter': True}})`.Refer to the official MathJax documentation for the appropriate configuration when using MathJax 3.x with the generated HTML output.
Always enclose your math expressions within the defined delimiters (`\(...\)`, `\[...\]`, `$$...$$`, or `$...$` if enabled). Ensure proper extension ordering if using multiple Markdown extensions that might process similar syntax.