Skip to main content

Math extension for Python-Markdown

Project description

Travis CI status

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 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 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://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js">
</script>

(replace 2.7.4 with the latest version if it is available).

Also, you need to specify a configuration for MathJax. Please note that most of standard configuratons include tex2jax extension, which is not needed with this code.

Example of MathJax configuration:

<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>

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 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-markdown-math-0.6.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_markdown_math-0.6-py2.py3-none-any.whl (3.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file python-markdown-math-0.6.tar.gz.

File metadata

File hashes

Hashes for python-markdown-math-0.6.tar.gz
Algorithm Hash digest
SHA256 c68d8cb9695cb7b435484403dc18941d1bad0ff148e4166d9417046a0d5d3022
MD5 ec55aba25c4e09eaeb07ded37336668a
BLAKE2b-256 78e124021b30466ca2985352ec1f15b3cb38e0b62ba742c46820c33ddf7114a8

See more details on using hashes here.

File details

Details for the file python_markdown_math-0.6-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for python_markdown_math-0.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d443e264cf063623a5f02b0c9730867e5172b31d49967da424ed3457c25b2848
MD5 e12900c5eb426bf8dabf939ed06b9a53
BLAKE2b-256 7c812c86570437821d77b90a6d939d54e11b507b71785850840a5e56d8febeca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page