Skip to main content

katex extension for Python Markdown

Project description

markdown-katex

This is an extension for Python Markdown which adds KaTeX support.

```math
f(x) = \int_{-\infty}^\infty
\hat f(\xi)\,e^{2 \pi i \xi x}
\,d\xi
```

Project/Repo:

MIT License Supported Python Versions PyCalVer v202005.0017 PyPI Version PyPI Downloads

Code Quality/CI:

Build Status Type Checked with mypy Code Coverage Code Style: sjfmt

Name role since until
Manuel Barkhau (mbarkhau@gmail.com) author/maintainer 2019-05 -

Install

$ pip install markdown-katex

This package includes the following binaries:

  • katex-v0.11.1-x86_64-Linux
  • katex-v0.11.1-x86_64-Macos
  • katex-v0.11.1-x86_64-Windows

If you are on a different platform, or want to use a more recent version of katex-cli, you will need to install it via npm.

$ npx katex
$ npx katex --version
0.10.2

This extension will always use the locally installed version of KaTeX if it is available, instead of using the implementation bundled with this package.

No JavaScript is required to render the resulting HTML, so it can be used with more limited renderers (which don't support JavaScript) such as WeasyPrint .

Usage

Formulas can be created and edited interactively using the editor on katex.org. They also have some good documentation for the subset of LaTeX that is supported. When embedding these in your Markdown files, they must be marked with a special syntax in order to be rendered using KaTeX. There are many syntax extensions for Markdown that allow LaTeX formulas to be embedded, however this package only supports the syntax introduced by Gitlab:

  • For inline mode formulas: $`...`$
  • For display mode formulas: ```math

Here is an example that uses this syntax.

There are two main advantages of this syntax:

  1. Gitlab has an existing Markdown renderer that can be used without the need to download any software. This implementation also uses KaTeX, so the output should be exactly the same as this extension.
  2. The fallback behaviour of other Markdown renderers is to render the raw LaTeX as inline code or a code block. This means that they won't inadvertently parse a LaTeX formula as Markdown syntax.

Hopefully other renderers will also adopt support for this syntax as:

  1. Rendering is done in the browser using KaTeX so implementation effort and should be minimal.
  2. The false positive rate for existing Markdown documents is negligible (ie. existing alternate use of $` syntax is minimal to non-existent).

Options

  • no_inline_svg: Replace inline <svg> with <img data:image/svg+xml;base64.."> tags.
  • insert_fonts_css: Insert font loading stylesheet (default: True).

Development/Testing

$ git clone https://gitlab.com/mbarkhau/markdown-katex
$ cd markdown-katex
$ make install
$ make lint mypy test

MkDocs Integration

In your mkdocs.yml add this to markdown_extensions.

% macros.tex
\mymacro:\text{prefix #1 suffix}
markdown_extensions:
  - markdown_katex:
      no_inline_svg: True
      insert_fonts_css: True
      macro-file: macros.tex

Changelog for https://gitlab.com/mbarkhau/markdown-katex

v202005.0017

v202005.0016-beta

v202004.0015-beta

v202004.0014-beta

v202001.0013-beta

  • Fix: Ignore trailing whitespace after closing fence.

v202001.0012-beta

  • Fix: Remove extraneous whitespace to work better with whitespace: pre.

v201912.0011-beta

  • Add option insert_fonts_css
  • Document options

v201910.0010-beta

  • Add more prominent example to README.md
  • Fix #2: Fix spurious log message when using MkDocs

v201908.0009-beta

  • Fix #1: Wrong formulas are rendered when multiple formulas are in one doc.

v201907.0008-beta

  • Fix: don't require typing package for py<35

v201905.0007-beta

  • Fix: Parsing of inline code when using multiple backticks

v201905.0004-beta

  • Fix: better error reporting
  • Fix: cleanup temp dir

v201905.0002-alpha

  • Initial release

Project details


Download files

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

Source Distribution

markdown-katex-202005.17.tar.gz (43.1 MB view details)

Uploaded Source

Built Distribution

markdown_katex-202005.17-py2.py3-none-any.whl (43.4 MB view details)

Uploaded Python 2 Python 3

File details

Details for the file markdown-katex-202005.17.tar.gz.

File metadata

  • Download URL: markdown-katex-202005.17.tar.gz
  • Upload date:
  • Size: 43.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200325 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

File hashes

Hashes for markdown-katex-202005.17.tar.gz
Algorithm Hash digest
SHA256 657a89e4d187bba60dcd53967a30adca74ca315c5b543269def6a8e505d7c184
MD5 58ec389d2f3711b5105f4b149ae42df8
BLAKE2b-256 60a2b46fa00a1515894fdcb84d015e0560ccb2b05c0ac5886c73776f4ac91fad

See more details on using hashes here.

File details

Details for the file markdown_katex-202005.17-py2.py3-none-any.whl.

File metadata

  • Download URL: markdown_katex-202005.17-py2.py3-none-any.whl
  • Upload date:
  • Size: 43.4 MB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200325 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

File hashes

Hashes for markdown_katex-202005.17-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 89944e62745e5edb60797346d5b48f939aa205073b6ba9b97d3840935d276dc0
MD5 c605af3b1a7949b75712c6c4309206bd
BLAKE2b-256 e04741cec3bb8915eeea9b12c4fee0d086cca90c9c81bcc49f3f9e88f83efab3

See more details on using hashes here.

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