1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
Metadata-Version: 2.4
Name: python-markdown-math
Version: 0.9
Summary: Math extension for Python-Markdown
Author-email: Dmitry Shachnev <mitya57@gmail.com>
License-Expression: BSD-3-Clause
Project-URL: Homepage, https://github.com/mitya57/python-markdown-math
Classifier: Development Status :: 5 - Production/Stable
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: Markup :: Markdown
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Markdown>=3.0
Dynamic: license-file
[][Actions]
[Actions]: https://github.com/mitya57/python-markdown-math/actions
Math extension for Python-Markdown
==================================
This extension adds math formulas support to [Python-Markdown].
[Python-Markdown]: https://github.com/Python-Markdown/markdown
Installation
------------
### Install from PyPI
```
$ pip install python-markdown-math
```
### Install locally
Use `pip install .` to install this extension from a local Git checkout.
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.
[Python-Markdown documentation]: https://python-markdown.github.io/reference/#extensions
Usage
-----
To use this extension, you need to include [MathJax] library in HTML files, like:
```html
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js">
</script>
```
[MathJax]: https://www.mathjax.org/
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:
```html
<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>
```
If you want to use MathJax 3.x, you need to teach it to understand 2.x-style
`<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 Python-Markdown, use `mdx_math` as extension name.
For example:
```python
>>> 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>
```
[upgrading documentation]: https://docs.mathjax.org/en/latest/upgrading/v2.html#math-script-example
[Arithmatex]: https://facelessuser.github.io/pymdown-extensions/extensions/arithmatex/
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 use [GitLab-style delimiters] (``$`...`$`` for inline math,
and a code block-like `` ```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.
[GitLab-style delimiters]: https://docs.gitlab.com/user/markdown/#math-equations
Notes
-----
If you use [ReText](https://github.com/retext-project/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>`:
```html
<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/mathtex-script-type.min.js" defer></script>
```
|