A Markdown extension for rendering LaTeX math using Katex
Project description
About md_katex
md_katex is a KaTeX plugin initially developed for use in personal blogs with Pelican. It focuses on rendering mathematical formulas directly in the browser using the KaTeX JavaScript library, rather than performing offline conversions.
Features
- Client-Side Rendering: Unlike other plugins, md_katex does not convert formulas offline. Instead, the KaTeX JavaScript file in the browser handles the rendering, making the publishing process simpler and more efficient.
- Supports Multiple Formula Delimiter Styles:
- GitLab Style: Use
$`
and`$
for inline formulas, and~~~math
code blocks for block-level formulas. - Brackets Style: Use
\(
and\)
for inline formulas, and\[
and\]
for block-level formulas. - GitHub Style: Use
$$
as both the opening and closing delimiters for block-level formulas.
- GitLab Style: Use
Installation
First, ensure that you have the python-markdown
library installed. Then, you can install this plugin using the following command:
pip install md_katex
The generated HTML will include KaTeX formulas, and you will need to load KaTeX JavaScript on the frontend to complete the rendering.
To ensure proper rendering, include the KaTeX script via a <script>
tag in your HTML page. For example, using a CDN:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css" integrity="sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js" integrity="sha384-7zkQWkzuo3B5mTepMUcHkMB5jZaolc2xDwL6VFqjFALcbeS9Ggm/Yr2r3Dy4lfFg" crossorigin="anonymous"></script>
<script>document.addEventListener("DOMContentLoaded", function () {
var mathElements = document.getElementsByClassName("math");
var macros = [];
for (var i = 0; i < mathElements.length; i++) {
var texText = mathElements[i].firstChild;
if (mathElements[i].tagName == "SPAN" || mathElements[i].tagName === "DIV") {
katex.render(texText.data, mathElements[i], {
displayMode: mathElements[i].classList.contains('display'),
throwOnError: false,
macros: macros,
fleqn: false
});
}}});
</script>
References
- https://github.com/mbarkhau/markdown-katex
- https://github.com/martenlienen/pelican-katex
- https://github.com/oruelle/md_mermaid
- https://github.com/goessner/markdown-it-texmath
- https://docs.gitlab.com/ee/user/markdown.html#math
- https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/writing-mathematical-expressions
- https://katex.org/docs/autorender
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
File details
Details for the file md_katex-0.3.0.tar.gz
.
File metadata
- Download URL: md_katex-0.3.0.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eddb1948523d45be2e935b2e8fb073636a33990bc775288613049fd71472a559 |
|
MD5 | 728867843119355cb5fb79d8c838c006 |
|
BLAKE2b-256 | a8d51a82b9442edb99aed3f836eb25621b2228468234c8ada64e4ebafdadc198 |
File details
Details for the file md_katex-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: md_katex-0.3.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb8f3807b5f9ce9c9b735ef7180e1b761d1ad00dfd8e92806a55825658023e4b |
|
MD5 | d1896d5431d1cdca176c4544f2b0fbd0 |
|
BLAKE2b-256 | a0e48e21df650d35067784ac0761d339557e3c1011cb3ca8df1af2307e6b0dd3 |