markdown-latex-prerender


Namemarkdown-latex-prerender JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryAn extension to python-markdown that replaces inline latex with prerendered SVGs
upload_time2025-01-18 20:10:44
maintainerNone
docs_urlNone
authorAnton Lydike
requires_python<4.0,>=3.10
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Markdown LaTeX Prerenderer

This is a very simple [python-markdown](https://github.com/Python-Markdown/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:

```python
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:

```python
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](https://github.com/facelessuser/pymdown-extensions/blob/main/pymdownx/arithmatex.py)
in [facelessuser/pymdown-extensions](https://github.com/facelessuser/pymdown-extensions/blob/main/pymdownx/arithmatex.py).
I re-used a lot of their code. I guess it works.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "markdown-latex-prerender",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "Anton Lydike",
    "author_email": "me@antonlydike.de",
    "download_url": "https://files.pythonhosted.org/packages/6a/ec/ccd00398001895fac20508d7f22d4a8878341012f5657cd6d070fc26002a/markdown_latex_prerender-0.1.0.tar.gz",
    "platform": null,
    "description": "# Markdown LaTeX Prerenderer\n\nThis is a very simple [python-markdown](https://github.com/Python-Markdown/markdown) extension, similar to other markdon-latex implementations that adds support\nfor latex in markdown files.\n\nThe key differences to other approaches are:\n\n1. It does not require javascript on the client\n2. It does not require nodejs when building\n\nFor some reason, I could not find a way to render latex inside a markdown file without Javascript, that seemed crazy to\nme. So I built this tool. No KaTeX required. No NodeJS required. Just classic latex implementations.\n\n## How to use:\n\nMake sure you have `dvilualatex` and `dvisvgm` installed on your system.\n\nThen, add `LatexExtension` to your markdown extension list:\n\n```python\nimport markdown\nfrom markdown_latex_prerender import LatexExtension\n\nmarkdown.markdown(\n    md_str,\n    extensions=[\n        LatexExtension(),\n        ...\n    ],\n)\n```\n\n## How it works:\n\nIt uses the hosts `dvilualatex` and `dvisvgm` (both usually come with TexLive and friends) to convert a latex snippet to\nan svg file. **It does not ship either program itself. This is why it's less that 200 lines of code.\n\nDo not feed it untrusted input. It may break. Or worse.\n\n## Caching:\n\nYou may want to cache rendered things. For this, you can do something like this:\n\n```python\nfrom my_fav_caching_library import cache_function\n\nimport markdown_latex_prerenderer.render as render\n\nrender.render_latex = cache_function(render.render_latex)\n```\n\nOr whatever else you feel like doing.\n\n## Inpiration:\n\nSince I don't know how to build a python-markdown module to render inline-latex, I ~~asked chatGPT~~ looked at other\npeoples solutions. I found this: [arithmatex.py](https://github.com/facelessuser/pymdown-extensions/blob/main/pymdownx/arithmatex.py)\nin [facelessuser/pymdown-extensions](https://github.com/facelessuser/pymdown-extensions/blob/main/pymdownx/arithmatex.py).\nI re-used a lot of their code. I guess it works.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An extension to python-markdown that replaces inline latex with prerendered SVGs",
    "version": "0.1.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dcd5f0a3bfe6c5dd3e4d2f6e1e0079de144e2091208624d45cbcd89718335147",
                "md5": "fd35182f255260b64449b3a157da8ca1",
                "sha256": "32443d3025a178c9167421c3a16040c9264a6cffddc1f0bc304d8499f493ebab"
            },
            "downloads": -1,
            "filename": "markdown_latex_prerender-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fd35182f255260b64449b3a157da8ca1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 5416,
            "upload_time": "2025-01-18T20:10:41",
            "upload_time_iso_8601": "2025-01-18T20:10:41.924041Z",
            "url": "https://files.pythonhosted.org/packages/dc/d5/f0a3bfe6c5dd3e4d2f6e1e0079de144e2091208624d45cbcd89718335147/markdown_latex_prerender-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6aecccd00398001895fac20508d7f22d4a8878341012f5657cd6d070fc26002a",
                "md5": "32543f1db0cc9bb2f4d847f338020c16",
                "sha256": "ab2d7ca8d87ec814cd282647b86e4f9f37d2b2c948f47bec2019c38906b19062"
            },
            "downloads": -1,
            "filename": "markdown_latex_prerender-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "32543f1db0cc9bb2f4d847f338020c16",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 4561,
            "upload_time": "2025-01-18T20:10:44",
            "upload_time_iso_8601": "2025-01-18T20:10:44.057670Z",
            "url": "https://files.pythonhosted.org/packages/6a/ec/ccd00398001895fac20508d7f22d4a8878341012f5657cd6d070fc26002a/markdown_latex_prerender-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-18 20:10:44",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "markdown-latex-prerender"
}
        
Elapsed time: 1.33252s