A MkDocs plugin for server-side rendering of KaTeX math.
Project description
MkDocs KaTeX SSR Plugin
A MkDocs plugin that renders LaTeX math on the server side using KaTeX, offering faster load times, layout stability, and optional offline support.
[!NOTE] Maintenance Philosophy: This project is self-maintained. I welcome bug reports and corrections, but please note that I may not have the bandwidth to accept significant feature requests or major functional additions. Pull requests for bug fixes are appreciated.
This project's code and documentation were generated by Antigravity (Google DeepMind) and verified by the maintainer.
✨ Highlights
Traditional client-side rendering relies on JavaScript in the browser to convert LaTeX strings into HTML. This can lead to Layout Shift and slower performance. MkDocs KaTeX SSR pre-renders all math during the mkdocs build process using a local persistent process. The resulting HTML contains ready-to-view markup.
- 🚀 Ultra High Performance: Employs an advanced batch-IPC processing architecture for mathematical formulas, deeply decoupling Python and JavaScript serialization and lowering rendering overhead by up to $O(1)$ IPC calls per page.
- ⚡ Native Bun Support: Automatically detects and leverages the revolutionary
Bunruntime for faster startup and plugin execution. Seamlessly falls back toNode.jswhen Bun is unavailable. - 📦 Smart Dependency Management: Auto-installs KaTeX dependencies via
npmorbun addduring the first run if they are missing locally. - 🗃️ Built-in LMDB Cache: Recompilation is instantaneous thanks to the integrated ultra-fast LMDB engine (dynamic map size, starts at 32MB).
- 🔌 Offline Mode (Self-Contained): Safely enables the "Offline Mode" which pulls CSS, fonts, and scripts directly to your local site bundle.
- 🔄 Client-Side Fallback: Introduces a flexible
disableoption to revert to traditional client-side rendering while preserving asset management benefits.
📦 Installation
Prerequisites
- Bun or Node.js: Must be installed and available in your system PATH (
bunis recommended for optimal speed). - Python: 3.8+
Install Plugin
uv add mkdocs-katex-ssr
# or traditional pip
pip install mkdocs-katex-ssr
⚙️ Configuration
Add the plugin to your mkdocs.yml:
markdown_extensions:
- pymdownx.arithmatex:
generic: true
plugins:
- katex-ssr:
# --- Basic Configuration ---
use_bun: auto # Auto-detects Bun for improved compilation speed. Can be explicitly forced to true/false.
verbose: true # Enable build logs for each page detailing cache hits.
disable: false # Set to true to switch to client-side rendering only
add_katex_css: true # Required (true by default)
katex_css_filename: "katex-swap.min.css"
# --- Script Loading ---
ssr_contribs:
- mhchem # Loaded in the renderer for SSR
client_scripts:
- copy-tex # Injected as <script> tag for the browser
# --- KaTeX Options ---
katex_options:
macros:
"\\RR": "\\mathbb{R}"
Client-Side Only Mode (disable: true)
If you prefer to use KaTeX's traditional "Auto-render" extension instead of Server-Side Rendering (SSR), set disable: true.
[!IMPORTANT] When
disable: true,add_katex_cssmust betrue. Ifadd_katex_cssis set tofalse, the plugin will return a configuration error.
Offline Mode (Self-Contained)
Enable embed_assets to host all KaTeX files locally within your site.
plugins:
- katex-ssr:
embed_assets: true
🎛️ Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
use_bun |
bool/str | 'auto' |
Instructs the plugin to use the bun runtime for speed enhancements. Can be true, false, or 'auto'. |
disable |
bool | false |
If true, skips SSR and uses client-side "Auto-render". |
verbose |
bool | false |
Logs formula counts and processing time per page. |
katex_dist |
str | CDN URL | Base path for KaTeX (URL or local path). |
add_katex_css |
bool | true |
Whether to inject the CSS link tag. Must be true if disable is true. |
katex_css_filename |
str | katex.min.css |
The CSS filename to load. |
embed_assets |
bool | false |
Copies assets to output dir for offline support. |
ssr_contribs |
list | [] |
KaTeX contribs for SSR (or client if disable: true). |
client_scripts |
list | [] |
KaTeX contribs always injected for the browser. |
katex_options |
dict | {} |
Options passed to KaTeX (including macros). |
🛠️ Troubleshooting
- Validation Error: If you see "When 'disable' is true, 'add_katex_css' must also be true", ensure you haven't set
add_katex_css: falsewhile disabling SSR. - Runtime Error: Verify
nodeorbunis installed and registered in your environmentPATH.
📄 License
MIT License.
Generated by Antigravity (Google DeepMind) and verified manually by the maintainer.
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 Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mkdocs_katex_ssr-1.2.0.tar.gz.
File metadata
- Download URL: mkdocs_katex_ssr-1.2.0.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
257f9b0e26904cca1e1ea5d59f9057e4295a1c6e202f041315f36fbe72966778
|
|
| MD5 |
89e2b46c097592755a7a55332ed7e278
|
|
| BLAKE2b-256 |
98280ac978bfe5a1295567ff4f773e3a9b4dc109304b5bbd49e4598c67aaf718
|
Provenance
The following attestation bundles were made for mkdocs_katex_ssr-1.2.0.tar.gz:
Publisher:
publish.yml on raineblog/mkdocs-katex-ssr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mkdocs_katex_ssr-1.2.0.tar.gz -
Subject digest:
257f9b0e26904cca1e1ea5d59f9057e4295a1c6e202f041315f36fbe72966778 - Sigstore transparency entry: 1191385849
- Sigstore integration time:
-
Permalink:
raineblog/mkdocs-katex-ssr@cbd05d8827d5d226ec6edaf0f3ca2b7526246d2e -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/raineblog
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cbd05d8827d5d226ec6edaf0f3ca2b7526246d2e -
Trigger Event:
push
-
Statement type:
File details
Details for the file mkdocs_katex_ssr-1.2.0-py3-none-any.whl.
File metadata
- Download URL: mkdocs_katex_ssr-1.2.0-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f59efd3bfdc4f4942b2bb029d701313a2e2ff62f59b3da4fdb1ea65e104954a3
|
|
| MD5 |
e46d9e9168300ac48b227b3267a4ff47
|
|
| BLAKE2b-256 |
1832cacdc38719136cbe47e334531637f8096deadef2e530ef2517aef61de979
|
Provenance
The following attestation bundles were made for mkdocs_katex_ssr-1.2.0-py3-none-any.whl:
Publisher:
publish.yml on raineblog/mkdocs-katex-ssr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mkdocs_katex_ssr-1.2.0-py3-none-any.whl -
Subject digest:
f59efd3bfdc4f4942b2bb029d701313a2e2ff62f59b3da4fdb1ea65e104954a3 - Sigstore transparency entry: 1191385851
- Sigstore integration time:
-
Permalink:
raineblog/mkdocs-katex-ssr@cbd05d8827d5d226ec6edaf0f3ca2b7526246d2e -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/raineblog
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cbd05d8827d5d226ec6edaf0f3ca2b7526246d2e -
Trigger Event:
push
-
Statement type: