Python-Markdown extension to escape math expressions like $2\pi$
Project description
markdown_math_escape
Python-Markdown extension to escape math
expressions like $e^{i\pi} + 1 = 0$
.
Description
This extension protects math expressions from markdown parser so that no unexpected change will happen. Then, it converts their delimiters (enclosing special characters) to "brackets" styled delimiters which is supported by both MathJax and KaTeX. Since this extension does not render mathematics by itself:
- Pros: It does not slow markdown processing down... it's very fast.
- Cons: You need to setup either MathJax or KaTeX for client-side rendering.
From a user point of view, you can choose delimiters for writing as you like and you do not need to worry about conflict between markdown syntax and TeX syntax.
Installation
Firstly, install the extension by the command below:
pip install git+https://github.com/sgryjp/markdown_math_escape.git
Secondly, you need to let Python-Markdown to use it. How to do it depends on how you are using Python-Markdown. Please see examples section and find an example which is similar to your usage.
Options
An option delimiters
is available. See the table below for supported values.
delimiters |
Inline (non-display mode) | Display mode math |
---|---|---|
dollers |
$e^{i\pi} + 1 = 0$ |
$$ e^{i\pi} + 1 = 0 $$ |
brackets |
\(e^{i\pi} + 1 = 0\) |
\[ e^{i\pi} + 1 = 0 \] |
gitlab |
$`e^{i\pi} + 1 = 0`$ |
```math e^{i\pi} + 1 = 0 ``` |
Examples
Python script
If you are using Python-Markdown directly in your Python script (or library), just do so in the standard way. For example:
import markdown as md
from markdown_math_escape import MathEscapeExtension
md.markdown(
some_text,
extensions=[
"markdown.extensions.codehilite",
"markdown.extensions.extra",
MathEscapeExtension(delimiters="dollers"),
],
)
Please refer to the Python-Markdown's document for more details.
Pelican
If you are using Python-Markdown as part of
Pelican,
you can use extension name markdown_math_escape
. For example:
# pelicanconf.py
MARKDOWN = {
'extension_configs': {
# ...other extensions...
"markdown_math_escape": {"delimiters": "dollers"},
}
}
Please refer to the Pelican's document for more details.
Nikola
If you are using Python-Markdown as part of
Nikola,
you can use extension name markdown_math_escape
. For example:
# conf.py
MARKDOWN_EXTENSIONS = [
# ...other extensions...
'markdown_math_escape',
]
MARKDOWN_EXTENSION_CONFIGS = {
DEFAULT_LANG: {
"markdown_math_escape": {"delimiters": "dollers"},
},
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for markdown_math_escape-0.20.10.18-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdc4b55151a580bc7e97a0cae18071800ec827cac9dca84c3ac3c031013e90c3 |
|
MD5 | 437e91fd8d60a42df2161c9dfab56e7a |
|
BLAKE2b-256 | a287f867598d81d8ec81bbe984b3980edf1bbec40103ee3122d00e00a08ebf3d |