├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── LICENSE
├── MANIFEST.in
├── README.md
├── changelog
├── mdx_math.py
├── pyproject.toml
├── test.py
└── test_data
├── beginend.html
├── beginend.mkd
├── beginend_inside_inline.html
├── beginend_inside_inline.mkd
├── beginend_inside_standalone.html
├── beginend_inside_standalone.mkd
├── beginend_preview.html
├── inline.html
├── inline_asciimath.html
├── inline_asciimath.mkd
├── inline_gitlab.mkd
├── inline_inside_standalone.html
├── inline_inside_standalone.mkd
├── inline_latex.mkd
├── inline_latex_escaped.html
├── inline_latex_escaped.mkd
├── inline_latex_inside_code.html
├── inline_latex_inside_code.mkd
├── inline_preview.html
├── inline_tex.mkd
├── inline_tex_disabled.html
├── inline_tex_escaped.html
├── inline_tex_escaped.mkd
├── standalone.html
├── standalone_gitlab.html
├── standalone_gitlab.mkd
├── standalone_gitlab_nested.html
├── standalone_gitlab_nested.mkd
├── standalone_latex.mkd
├── standalone_latex_escaped.html
├── standalone_latex_escaped.mkd
├── standalone_preview.html
└── standalone_tex.mkd
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: tests
2 | on: [push, pull_request]
3 | jobs:
4 | test:
5 | runs-on: ubuntu-latest
6 | strategy:
7 | matrix:
8 | python:
9 | - '3.9'
10 | - '3.10'
11 | - '3.11'
12 | - '3.12'
13 | - '3.13'
14 | - pypy3.10
15 | steps:
16 | - uses: actions/checkout@v4
17 | - uses: actions/setup-python@v5
18 | with:
19 | python-version: ${{ matrix.python }}
20 | - run: pip install Markdown
21 | - run: python ./test.py
22 | pypi-publish:
23 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
24 | runs-on: ubuntu-latest
25 | environment:
26 | name: pypi
27 | url: https://pypi.org/p/python-markdown-math
28 | permissions:
29 | id-token: write
30 | steps:
31 | - uses: actions/checkout@v4
32 | - uses: actions/setup-python@v5
33 | with:
34 | python-version: '3.13'
35 | - run: pip install build
36 | - run: python -m build
37 | - if: success()
38 | uses: pypa/gh-action-pypi-publish@release/v1
39 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 | dist
3 | MANIFEST
4 | *.pyc
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2015-2025 Dmitry Shachnev
79 | 80 |
81 | ``` 82 | 83 | [upgrading documentation]: https://docs.mathjax.org/en/latest/upgrading/v2.html#math-script-example 84 | [Arithmatex]: https://facelessuser.github.io/pymdown-extensions/extensions/arithmatex/ 85 | 86 | Math Delimiters 87 | --------------- 88 | 89 | For inline math, use `\(...\)`. 90 | 91 | For standalone math, use `$$...$$`, `\[...\]` or `\begin...\end`. 92 | 93 | The single-dollar delimiter (`$...$`) for inline math is disabled by 94 | default, but can be enabled by passing `enable_dollar_delimiter=True` 95 | in the extension configuration. 96 | 97 | If you want to use [GitLab-style delimiters] (``$`...`$`` for inline math, 98 | and a code block-like `` ```math...``` `` syntax for standalone), use 99 | `use_gitlab_delimiters=True` configuration option. 100 | 101 | If you want to this extension to generate a preview node (which will be shown 102 | when MathJax has not yet processed the node, or when JavaScript is unavailable), 103 | use `add_preview=True` configuration option. 104 | 105 | [GitLab-style delimiters]: https://docs.gitlab.com/user/markdown/#math-equations 106 | 107 | Notes 108 | ----- 109 | 110 | If you use [ReText](https://github.com/retext-project/retext), this extension 111 | is not needed as it is included by default. 112 | 113 | This extension also works with Katex. Use the following in your page ``: 114 | 115 | ```html 116 | 117 | 118 | 119 | ``` 120 | -------------------------------------------------------------------------------- /changelog: -------------------------------------------------------------------------------- 1 | Version 0.9, 2025-04-10 2 | ======================= 3 | 4 | * Fixed handling of begin/end inside inline math. 5 | - Thanks to Tianxiang Xia for the bug report. 6 | * Modernized packaging. 7 | * Python ≥ 3.9 and setuptools ≥ 77.0 are now required. 8 | 9 | Version 0.8, 2020-11-03 10 | ======================= 11 | 12 | * GitLab-style math blocks are now supported in nested environments such 13 | as lists. 14 | - Thanks to Ran Shaham for the contribution. 15 | * Tests now pass with Python-Markdown 3.3. 16 | 17 | Version 0.7, 2020-06-19 18 | ======================= 19 | 20 | * This extension now requires Python ≥ 3.4 and Python-Markdown ≥ 3.0. 21 | * Fixed deprecation warnings with Python-Markdown 3.x. 22 | * Added support for GitLab-style delimiters. 23 | 24 | Version 0.6, 2018-06-13 25 | ======================= 26 | 27 | * Include LICENSE and tests in the tarball. 28 | 29 | Version 0.5, 2018-05-03 30 | ======================= 31 | 32 | * Re-upload with fixed metadata and description. 33 | 34 | Version 0.4, 2018-05-03 35 | ======================= 36 | 37 | * Added AsciiMath support. To switch from LaTeX syntax to AsciiMath, 38 | set the “use_asciimath” configuration option to true. 39 | * The dollar sign can now be escaped when the “enable_dollar_delimiter” 40 | option is enabled (\$ produces $). 41 | * Inline math can now be used inside standalone math. 42 | 43 | Version 0.3, 2017-03-24 44 | ======================= 45 | 46 | * Added “add_preview” configuration option, which adds preview nodes 47 | as recognized by MathJax before every script node. 48 | - Thanks to Antoine Amarilli and Danni Randeris for their initial work. 49 | * Added a test suite. 50 | * Documentation improvements. 51 | 52 | Version 0.2, 2015-12-05 53 | ======================= 54 | 55 | * Fix compatibility with earlier Python-Markdown versions. 56 | - Thanks to Bryan A. Jones for the contribution. 57 | * Add installation instructions from PyPI. 58 | - Thanks to Drew Hubl for the contribution. 59 | 60 | Version 0.1, 2015-08-12 61 | ======================= 62 | 63 | * Initial release. 64 | -------------------------------------------------------------------------------- /mdx_math.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Math extension for Python-Markdown 3 | ================================== 4 | 5 | Adds support for displaying math formulas using 6 | [MathJax](http://www.mathjax.org/). 7 | 8 | Author: 2015-2025, Dmitry Shachnev2 | 8 |
9 | -------------------------------------------------------------------------------- /test_data/beginend.mkd: -------------------------------------------------------------------------------- 1 | \begin{equation*} 2 | \begin{pmatrix} 3 | 1 & 0\\ 4 | 0 & 1 5 | \end{pmatrix} 6 | \end{equation*} 7 | -------------------------------------------------------------------------------- /test_data/beginend_inside_inline.html: -------------------------------------------------------------------------------- 1 |2 | 3 |
4 | -------------------------------------------------------------------------------- /test_data/beginend_inside_inline.mkd: -------------------------------------------------------------------------------- 1 | \( T(v) = \begin{bmatrix}\alpha & \beta \\ \gamma & \delta \end{bmatrix} \) 2 | -------------------------------------------------------------------------------- /test_data/beginend_inside_standalone.html: -------------------------------------------------------------------------------- 1 |2 | 9 |
10 | -------------------------------------------------------------------------------- /test_data/beginend_inside_standalone.mkd: -------------------------------------------------------------------------------- 1 | $$ 2 | s(x) = \begin{cases} 3 | 1 & \text{if } x > 0\\ 4 | 0 & \text{if } x = 0\\ 5 | -1 & \text{if } x < 0 6 | \end{cases} 7 | $$ 8 | -------------------------------------------------------------------------------- /test_data/beginend_preview.html: -------------------------------------------------------------------------------- 1 |2 |
Inline math: .
2 | -------------------------------------------------------------------------------- /test_data/inline_asciimath.html: -------------------------------------------------------------------------------- 1 |2 | 3 |
4 | -------------------------------------------------------------------------------- /test_data/inline_asciimath.mkd: -------------------------------------------------------------------------------- 1 | \( sum_(i=1)^n i^3=((n(n+1))/2)^2 \) 2 | -------------------------------------------------------------------------------- /test_data/inline_gitlab.mkd: -------------------------------------------------------------------------------- 1 | Inline math: $`e^{i \varphi}`$. 2 | -------------------------------------------------------------------------------- /test_data/inline_inside_standalone.html: -------------------------------------------------------------------------------- 1 |2 | 3 |
4 | -------------------------------------------------------------------------------- /test_data/inline_inside_standalone.mkd: -------------------------------------------------------------------------------- 1 | \[ \sqrt{\text{ number of \(B\)-words }} \] 2 | -------------------------------------------------------------------------------- /test_data/inline_latex.mkd: -------------------------------------------------------------------------------- 1 | Inline math: \(e^{i \varphi}\). 2 | -------------------------------------------------------------------------------- /test_data/inline_latex_escaped.html: -------------------------------------------------------------------------------- 1 |Inline math: \(e^{i \varphi}\).
2 | -------------------------------------------------------------------------------- /test_data/inline_latex_escaped.mkd: -------------------------------------------------------------------------------- 1 | Inline math: \\(e^{i \varphi}\\). 2 | -------------------------------------------------------------------------------- /test_data/inline_latex_inside_code.html: -------------------------------------------------------------------------------- 1 |\(e^{i \varphi}\)
Inline math: \(e^{i \varphi}\).
2 | -------------------------------------------------------------------------------- /test_data/inline_tex.mkd: -------------------------------------------------------------------------------- 1 | Inline math: $e^{i \varphi}$. 2 | -------------------------------------------------------------------------------- /test_data/inline_tex_disabled.html: -------------------------------------------------------------------------------- 1 |Inline math: $e^{i \varphi}$.
2 | -------------------------------------------------------------------------------- /test_data/inline_tex_escaped.html: -------------------------------------------------------------------------------- 1 |Escaped $ dollar sign and real .
2 | -------------------------------------------------------------------------------- /test_data/inline_tex_escaped.mkd: -------------------------------------------------------------------------------- 1 | Escaped \$ dollar sign and real $math$. 2 | -------------------------------------------------------------------------------- /test_data/standalone.html: -------------------------------------------------------------------------------- 1 |2 | 6 |
7 | -------------------------------------------------------------------------------- /test_data/standalone_gitlab.html: -------------------------------------------------------------------------------- 1 | 5 | 6 | 9 | -------------------------------------------------------------------------------- /test_data/standalone_gitlab.mkd: -------------------------------------------------------------------------------- 1 | ```math 2 | e^{i \varphi} = 3 | \cos \varphi + i \sin \varphi 4 | ``` 5 | 6 | ```math 7 | \text{one more math block} 8 | ``` 9 | -------------------------------------------------------------------------------- /test_data/standalone_gitlab_nested.html: -------------------------------------------------------------------------------- 1 |\[ 2 | e^{i \varphi} = 3 | \cos \varphi + i \sin \varphi 4 | \]
5 | -------------------------------------------------------------------------------- /test_data/standalone_latex_escaped.mkd: -------------------------------------------------------------------------------- 1 | \\[ 2 | e^{i \varphi} = 3 | \cos \varphi + i \sin \varphi 4 | \\] 5 | -------------------------------------------------------------------------------- /test_data/standalone_preview.html: -------------------------------------------------------------------------------- 1 |2 |