Math extension for Python-Markdown
This extension adds math formulas support to Python-Markdown.
Installation
Install from PyPI
$ pip install python-markdown-math
Install locally
Use pip install . to install this extension from a local Git checkout.
The extension name is mdx_math, so you need to add that name to your
list of Python-Markdown extensions.
Check Python-Markdown documentation for details on how to load
extensions.
Usage
To use this extension, you need to include MathJax library in HTML files, like:
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js">
</script>
Also, you need to specify a configuration for MathJax. Please note that
most of standard configurations include tex2jax extension, which is not needed
with this code.
Example of configuration for MathJax 2.x:
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
config: ["MMLorHTML.js"],
jax: ["input/TeX", "output/HTML-CSS", "output/NativeMML"],
extensions: ["MathMenu.js", "MathZoom.js"]
});
</script>
If you want to use MathJax 3.x, you need to teach it to understand 2.x-style
<script> tags. See the upgrading documentation on how to do it.
Alternatively, you may use the Arithmatex extension which has a generic
output mode, that does not require such special configuration.
To pass the extension to Python-Markdown, use mdx_math as extension name.
For example:
>>> md = markdown.Markdown(extensions=['mdx_math'])
>>> md.convert('$$e^x$$')
'<p>\n<script type="math/tex; mode=display">e^x</script>\n</p>'
Usage from the command line:
$ echo "\(e^x\)" | python3 -m markdown -x mdx_math
<p>
<script type="math/tex">e^x</script>
</p>
Math Delimiters
For inline math, use \(...\).
For standalone math, use $$...$$, \[...\] or \begin...\end.
The single-dollar delimiter ($...$) for inline math is disabled by
default, but can be enabled by passing enable_dollar_delimiter=True
in the extension configuration.
If you want to use GitLab-style delimiters ($`...`$ for inline math,
and a code block-like ```math...``` syntax for standalone), use
use_gitlab_delimiters=True configuration option.
If you want to this extension to generate a preview node (which will be shown
when MathJax has not yet processed the node, or when JavaScript is unavailable),
use add_preview=True configuration option.
Notes
If you use ReText, this extension is not needed as it is included by default.
This extension also works with Katex. Use the following in your page <head>:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex/dist/katex.min.css" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/katex/dist/katex.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/katex/dist/contrib/mathtex-script-type.min.js" defer></script>
Metadata
Release files for python-markdown-math 0.9
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 | |
|---|---|---|---|---|
| python_markdown_math-0.9.tar.gz | 8.7 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| python_markdown_math-0.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.7 kB
Release files / python_markdown_math-0.9.tar.gz
| Download URL | python_markdown_math-0.9.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
567395553dc4941e79b3789a1096dcabb3fda9539d150d558ef3507948b264a3
|
|
BLAKE2b-256 checksum How to use checksums |
4c68fbea05ec6fb318bdcf56ea47596605614554f51d77bfd14f6fb481139ad8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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 Apr 10, 2025.
Transparency logRelease files / python_markdown_math-0.9-py3-none-any.whl
| Download URL | python_markdown_math-0.9-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ac9932df517a5c0f6d01c56e7a44d065eca4a420893ac45f7a6937c67cb41e86
|
|
BLAKE2b-256 checksum How to use checksums |
eb68ecf3535c40845de2efd8ac2d092dd5fca0868219fa3684d9e58ef7abeece
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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 Apr 10, 2025.
Transparency logSecurity for python-markdown-math 0.9
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
All 2 files in this release have been uploaded with provenance metadata.
Attestation for python_markdown_math-0.9.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 Apr 10, 2025.
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.