Math extension for Python-Markdown
Low maintenance activity. Last release 20 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and recent releases.
pip install python-markdown-mathMath 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>