Skip to main content

PyKaTeX

A Python wrapper for the KaTeX library, providing fast server-side rendering of mathematical expressions.

PyKaTeX uses a C extension module with QuickJS-NG to enable Python to call into KaTeX, which is written in Javascript. The current version of PyKaTeX uses KaTeX v0.16.22 and QuickJS-NG v0.10.1.

⚠️ PyKaTex is currently in alpha. Some options are only partially supported (see the "usage" section for more information) and KaTeX exceptions are not handled gracefully yet.

Installation

pip install pykatex

Or, to install from source, clone the repository and run

pip install .

in the root of this repository.

Usage

PyKaTeX provides a single function renderToString that takes a LaTeX string and optional keyword arguments:

pykatex.renderToString(input, **options)

It can be used as follows:

import pykatex as katex

html = katex.renderToString("E = mc^2",
                            displayMath=True,
                            output="html")

print(html)

Refer to the KaTeX documentation for the available options and their defaults.

Currently, there are the following limitations:

  • The macros option is not yet implemented
  • Currently only string and boolean values are supported for the strict option (functions are not supported)

Using the output

To view the rendered formula, you need to include KaTeX CSS in your HTML. You can use the following template:

<!-- KaTeX requires the use of the HTML5 doctype. Without it, KaTeX may not render properly -->
<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.22/dist/katex.min.css" integrity="sha384-5TcZemv2l/9On385z///+d7MSYlvIEw9FuZTIdZ14vJLqWphw7e7ZPuOiCHJcFCP" crossorigin="anonymous">
  </head>
  <body>
    <!-- include the output from renderToString here -->
  </body>
</html>

The stylesheet katex.min.css that the template links to is also vendored in the source here, as src/katex/katex.min.css. You can also host it yourself and use that, if you like.

Architecture

PyKaTeX consists of:

  • A Python C extension module (pykatex.c) that provides the Python interface
  • QuickJS JavaScript engine (src/quickjs/) for executing KaTeX
  • A wrapper script (katex.js) that calls into the KaTeX library (src/katex/)
  • QuickJS bytecode (katex.bytecode.h) for the wrapper script, generated by the QuickJS-NG compiler qjs
  • C wrapper code (katex.c) that bridges Python and JavaScript

The katex.bytecode.h file is generated by running

quickjs/build/qjsc -e -N katex -o katex.bytecode.h katex.js

in the src/ folder, and manually remove the JS_NewCustomContext and main functions. This needs to be done again when the wrapper script or KaTeX library is changed (for example, when KaTeX is updated to a new version).

License

This project bundles KaTeX and QuickJS-NG. Please refer to their respective licenses for terms and conditions.

Metadata

Release files for PyKaTeX 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyKaTeX 0.1.1
File Size Uploaded
pykatex-0.1.1.tar.gz 1.0 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for PyKaTeX 0.1.1
File
pykatex-0.1.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
pykatex-0.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
pykatex-0.1.1-cp313-cp313-macosx_10_13_universal2.whl CPython 3.13 CPython 3.13 macOS 10.13+ universal2 (ARM64, x86-64) Details
pykatex-0.1.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
pykatex-0.1.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
pykatex-0.1.1-cp312-cp312-macosx_10_13_universal2.whl CPython 3.12 CPython 3.12 macOS 10.13+ universal2 (ARM64, x86-64) Details
pykatex-0.1.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
pykatex-0.1.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
pykatex-0.1.1-cp311-cp311-macosx_10_9_universal2.whl CPython 3.11 CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64) Details
pykatex-0.1.1-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
pykatex-0.1.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
pykatex-0.1.1-cp310-cp310-macosx_10_9_universal2.whl CPython 3.10 CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) Details
pykatex-0.1.1-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
pykatex-0.1.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
pykatex-0.1.1-cp39-cp39-macosx_10_9_universal2.whl CPython 3.9 CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64) Details

Total release size: 31.2 MB

Release files / pykatex-0.1.1.tar.gz

Download URL pykatex-0.1.1.tar.gz
Size 1.0 MB
Tags Source
SHA-256 checksum
How to use checksums
22809068e7e1f41a50a3475805adf0bfea4893245f1dac9699d426fa06a2b165
BLAKE2b-256 checksum
How to use checksums
61d99617bd5f716908115943a9b2aff95df59d9ec032f5fd886fcab0657a11c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pykatex-0.1.1-cp313-cp313-win_amd64.whl

Download URL pykatex-0.1.1-cp313-cp313-win_amd64.whl
Size 1.1 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
fa75f3dd2853e0a51a454445880d6def1ac328bdb324761eaea954f39a2b9b30
BLAKE2b-256 checksum
How to use checksums
ce543f0e3c1ca99e431716e474d0ab1e18a947695fd09066c9673a69dfe86e92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pykatex-0.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL pykatex-0.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 2.9 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
568c2a0951a03460dca44f9289824ac6f9e3ded777267efd30ff69c8da209e99
BLAKE2b-256 checksum
How to use checksums
c6174e9216ec7fb5b4f4e95dcfa8b932d5b683344b2260a3f54233d3447b8069
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pykatex-0.1.1-cp313-cp313-macosx_10_13_universal2.whl

Download URL pykatex-0.1.1-cp313-cp313-macosx_10_13_universal2.whl
Size 2.0 MB
Tags CPython 3.13 macOS 10.13+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
bb803bc28bbe0f3bdb3ebb7343a22d4b79b0d6801692934eacc9465f2a094196
BLAKE2b-256 checksum
How to use checksums
b224d3b5f2012a09ce320ab49146f2b0a7656aa11ae56db4ae70fc074cdade36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pykatex-0.1.1-cp312-cp312-win_amd64.whl

Download URL pykatex-0.1.1-cp312-cp312-win_amd64.whl
Size 1.1 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
222d9c02b273530f21933e4425ffe525788a67f33a280be942dead1674d7a76f
BLAKE2b-256 checksum
How to use checksums
195b4d907b5f3ca1e4ca24a01ce76d5efa80974d13701c02e5de881a601d74b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pykatex-0.1.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL pykatex-0.1.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 2.9 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
41bbfdd6fc09362a4d7758b36497c077f5b779a25bba2e375d653f807427a873
BLAKE2b-256 checksum
How to use checksums
97f29173af3b50bc4c2c7c00d39f69deb4513a89ab2d4f1a7ca1276a933fe7eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pykatex-0.1.1-cp312-cp312-macosx_10_13_universal2.whl

Download URL pykatex-0.1.1-cp312-cp312-macosx_10_13_universal2.whl
Size 2.0 MB
Tags CPython 3.12 macOS 10.13+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
72a874c4703a5f3f14845ac723b4327f4206cee695076286996b264c48554c57
BLAKE2b-256 checksum
How to use checksums
c59c4d8a8235e7ee6da137a76bbde6d9d025e31b32b447148d51f17abd6b5979
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pykatex-0.1.1-cp311-cp311-win_amd64.whl

Download URL pykatex-0.1.1-cp311-cp311-win_amd64.whl
Size 1.1 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
ff5c6c9202fa6ed8e22b80928ba2903e87bc43f0351c4fc15495b28fc9036a13
BLAKE2b-256 checksum
How to use checksums
a025b3d41dd9160a6bb59e12d9042ec76a5aa3f81ed4c33ec81c3393d61c0895
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pykatex-0.1.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL pykatex-0.1.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 2.9 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
92052672af7166a6fd0fae03a8b8f650e6c3163a2830f2045ac53a1feacd8286
BLAKE2b-256 checksum
How to use checksums
98dca715cbd1914b3bf5d993fc67c5f244af5d689c9faeba6eb446556b85fbe6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pykatex-0.1.1-cp311-cp311-macosx_10_9_universal2.whl

Download URL pykatex-0.1.1-cp311-cp311-macosx_10_9_universal2.whl
Size 2.0 MB
Tags CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
03cd071ab3f25f7d7c37ee410fd278d81b1c5a4f3804e911ab09474cc7560eab
BLAKE2b-256 checksum
How to use checksums
19926477398807eb188ed0f57b427451be3c6ad84c99ba091c91b6a78d262a69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pykatex-0.1.1-cp310-cp310-win_amd64.whl

Download URL pykatex-0.1.1-cp310-cp310-win_amd64.whl
Size 1.1 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
ba2920c077f49c2f207b2c620d8f84de3d855907466ff77555d4ca8befe9f711
BLAKE2b-256 checksum
How to use checksums
45b0027cada76cf348dcd997461887f1e6d51e1aa8d221c063b16628cd3c7fdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pykatex-0.1.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL pykatex-0.1.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 2.9 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
2a573820d8ca792336404aef81c030d26e71c653f347f7cad3fb8337d8e1dcb8
BLAKE2b-256 checksum
How to use checksums
686422589256e93e395ecb30602472ea49514b5aae5c8c2c17c508ff73a66a4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pykatex-0.1.1-cp310-cp310-macosx_10_9_universal2.whl

Download URL pykatex-0.1.1-cp310-cp310-macosx_10_9_universal2.whl
Size 2.0 MB
Tags CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
b86d90ce018a804dc8dbba14ee69af415de81493dfc196cbbce1489bcb26c13c
BLAKE2b-256 checksum
How to use checksums
b7667bf3dedffc33aee3900a800bf7e4a3e2f759569d99d03887ae26d641f2ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pykatex-0.1.1-cp39-cp39-win_amd64.whl

Download URL pykatex-0.1.1-cp39-cp39-win_amd64.whl
Size 1.1 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
cbc68206655e440424d0cdfea89f95bc1e84fd7894a831ad5f784f7c5ece492d
BLAKE2b-256 checksum
How to use checksums
a08345f62a56c087aa6b709c2c3628d77d1cf8448ceb149553675c9a0e1a7ab9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pykatex-0.1.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL pykatex-0.1.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 2.9 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
3d8cf8d2bf31676109d7a5174fe89ca7f2648f4b26d6624c276ae5388fc7910e
BLAKE2b-256 checksum
How to use checksums
11f3cb65e314818b6a4535bc629b05b6834a63d60250e797335845c0374f392e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pykatex-0.1.1-cp39-cp39-macosx_10_9_universal2.whl

Download URL pykatex-0.1.1-cp39-cp39-macosx_10_9_universal2.whl
Size 2.0 MB
Tags CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
3bfeac8649aef883200017632d1e688be3da09d7c22a8d8476922ffffade96dd
BLAKE2b-256 checksum
How to use checksums
021dadfd552006885805157c1c66f4f3ecad4859084bc413ada644275e82b473
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.1.1 This release

16 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page