Skip to main content

An extension to python-markdown that replaces inline latex with prerendered SVGs

Project description

Markdown LaTeX Prerenderer

This is a very simple python-markdown extension, similar to other markdon-latex implementations that adds support for latex in markdown files.

The key differences to other approaches are:

  1. It does not require javascript on the client
  2. It does not require nodejs when building

For some reason, I could not find a way to render latex inside a markdown file without Javascript, that seemed crazy to me. So I built this tool. No KaTeX required. No NodeJS required. Just classic latex implementations.

How to use:

Make sure you have dvilualatex and dvisvgm installed on your system.

Then, add LatexExtension to your markdown extension list:

import markdown
from markdown_latex_prerender import LatexExtension

markdown.markdown(
    md_str,
    extensions=[
        LatexExtension(),
        ...
    ],
)

How it works:

It uses the hosts dvilualatex and dvisvgm (both usually come with TexLive and friends) to convert a latex snippet to an svg file. **It does not ship either program itself. This is why it's less that 200 lines of code.

Do not feed it untrusted input. It may break. Or worse.

Caching:

You may want to cache rendered things. For this, you can do something like this:

from my_fav_caching_library import cache_function

import markdown_latex_prerenderer.render as render

render.render_latex = cache_function(render.render_latex)

Or whatever else you feel like doing.

Inpiration:

Since I don't know how to build a python-markdown module to render inline-latex, I asked chatGPT looked at other peoples solutions. I found this: arithmatex.py in facelessuser/pymdown-extensions. I re-used a lot of their code. I guess it works.

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_latex_prerender-0.1.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

markdown_latex_prerender-0.1.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file markdown_latex_prerender-0.1.1.tar.gz.

File metadata

  • Download URL: markdown_latex_prerender-0.1.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for markdown_latex_prerender-0.1.1.tar.gz
Algorithm Hash digest
SHA256 535e67bb5493c29859b39302cab7aae26960f9bf46718fcbc7ad9afe7c59ec5d
MD5 1c0fe263368c7461943c2e78d4e510dc
BLAKE2b-256 41ece1a8598f9684db7498aa92c8ccbbeea009f9d95b19cefc1c6820d13aa7d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for markdown_latex_prerender-0.1.1.tar.gz:

Publisher: pythonpublish.yml on AntonLydike/markdown_latex_prerender

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file markdown_latex_prerender-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for markdown_latex_prerender-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 98a4aaed2da1f0f60cb09454d7fdf99e5c7d591099cc09fd55c7f205930b0e33
MD5 f17736bb4a5906f78e9f28ef88ccf642
BLAKE2b-256 956ba19306780ffe9bbd1b2c09415857f596118492063d293bb739aad5bd8e22

See more details on using hashes here.

Provenance

The following attestation bundles were made for markdown_latex_prerender-0.1.1-py3-none-any.whl:

Publisher: pythonpublish.yml on AntonLydike/markdown_latex_prerender

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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