Skip to main content

Python-Markdown extension to escape math expressions like $2\pi$

Project description

markdown_math_escape

Test

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

markdown_math_escape-0.20.10.18-py3-none-any.whl (6.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page