Math extension for PythonMarkdown
Project description
Math extension for PythonMarkdown
This extension adds math formulas support to PythonMarkdown.
Installation
Install from PyPI
$ pip install pythonmarkdownmath
Install locally
Use setup.py build
and setup.py install
to build and install this
extension, respectively.
The extension name is mdx_math
, so you need to add that name to your
list of PythonMarkdown extensions.
Check PythonMarkdown 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/xmathjaxconfig"> MathJax.Hub.Config({ config: ["MMLorHTML.js"], jax: ["input/TeX", "output/HTMLCSS", "output/NativeMML"], extensions: ["MathMenu.js", "MathZoom.js"] }); </script>
If you want to use MathJax 3.x, you need to teach it to understand 2.xstyle
<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 PythonMarkdown, 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 singledollar 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 GitLabstyle delimiters ($`...`$
for inline math,
and a code blocklike ```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/mathtexscripttype.min.js" defer></script>
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size  File type  Python version  Upload date  Hashes 

Filename, size python_markdown_math0.8py3noneany.whl (5.9 kB)  File type Wheel  Python version py3  Upload date  Hashes View 
Filename, size pythonmarkdownmath0.8.tar.gz (8.5 kB)  File type Source  Python version None  Upload date  Hashes View 
Hashes for python_markdown_math0.8py3noneany.whl
Algorithm  Hash digest  

SHA256  c685249d84b5b697e9114d7beb352bd8ca2e07fd268fd4057ffca888c14641e5 

MD5  74e793e81f5d0723b0e10c756dd457f3 

BLAKE2256  4d36d16118345ff5f503d4d1c708e8427ed2213f2af7aaffac9d59010e665b5c 