Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Math extension for Python-Markdown

License

NotificationsYou must be signed in to change notification settings

mitya57/python-markdown-math

Repository files navigation

Build Status

Math extension for Python-Markdown

This extension adds math formulas support toPython-Markdown.

Installation

Install from PyPI

$ pip install python-markdown-math

Install locally

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.

Usage

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>

Math Delimiters

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

Notes

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

Stars

Watchers

Forks

Contributors5


[8]ページ先頭

©2009-2025 Movatter.jp