- Notifications
You must be signed in to change notification settings - Fork27
Math extension for Python-Markdown
License
mitya57/python-markdown-math
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This extension adds math formulas support toPython-Markdown.
$ pip install python-markdown-math
Usepip install .
to install this extension from a local Git checkout.
The extension name ismdx_math
, so you need to add that name to yourlist of Python-Markdown extensions.CheckPython-Markdown documentation for details on how to loadextensions.
To use this extension, you need to includeMathJax library in HTML files, like:
<scripttype="text/javascript"src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js"></script>
Also, you need to specify a configuration for MathJax. Please note thatmost of standard configurations includetex2jax
extension, which is not neededwith this code.
Example of configuration for MathJax 2.x:
<scripttype="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 theupgrading documentation on how to do it.Alternatively, you may use theArithmatex extension which has a genericoutput mode, that does not require such special configuration.
To pass the extension to Python-Markdown, usemdx_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>
For inline math, use\(...\)
.
For standalone math, use$$...$$
,\[...\]
or\begin...\end
.
The single-dollar delimiter ($...$
) for inline math is disabled bydefault, but can be enabled by passingenable_dollar_delimiter=True
in the extension configuration.
If you want to useGitLab-style delimiters ($`...`$
for inline math,and a code block-like```math...```
syntax for standalone), useuse_gitlab_delimiters=True
configuration option.
If you want to this extension to generate a preview node (which will be shownwhen MathJax has not yet processed the node, or when JavaScript is unavailable),useadd_preview=True
configuration option.
If you useReText, this extensionis not needed as it is included by default.
This extension also works with Katex. Use the following in your page<head>
:
<linkrel="stylesheet"href="https://cdn.jsdelivr.net/npm/katex/dist/katex.min.css"crossorigin="anonymous"><scriptsrc="https://cdn.jsdelivr.net/npm/katex/dist/katex.min.js"crossorigin="anonymous"></script><scriptsrc="https://cdn.jsdelivr.net/npm/katex/dist/contrib/mathtex-script-type.min.js"defer></script>
About
Math extension for Python-Markdown
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
Contributors5
Uh oh!
There was an error while loading.Please reload this page.