A Python wrapper for the KaTeX library, providing fast server-side rendering of mathematical expressions.
Project description
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
macrosoption is not yet implemented - Currently only string and boolean values are supported for the
strictoption (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 compilerqjs - 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.
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
Built Distributions
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 pykatex-0.1.0.tar.gz.
File metadata
- Download URL: pykatex-0.1.0.tar.gz
- Upload date:
- Size: 1.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
497a8bb54fb41b7bc21ffda78d1d4c3c39d865b4ed6270d644538fe050301756
|
|
| MD5 |
78a2ca82c4c0098dba13e1a87acd4123
|
|
| BLAKE2b-256 |
ffdb8ac8193aeb7af7c80d947fd6e7f8521a753c958c65df09dc6af6f99c130f
|
File details
Details for the file pykatex-0.1.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: pykatex-0.1.0-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c6f9c4d96fc844c87dbbb98348b55f69d9ffeb6dc9a97d375076ed9073c9fe9
|
|
| MD5 |
dfaefc3de41ff8febe6e43038bfbc2f7
|
|
| BLAKE2b-256 |
e8cad4ef7317c3abea215154a1ae7e5ee8fd2ab4154ec57429771e13a9439ff0
|
File details
Details for the file pykatex-0.1.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pykatex-0.1.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ed1a3e70f6b9330d092db3ad978be468564c5e433a449dfda027258bb8cd076
|
|
| MD5 |
2e3af7fb1342e82b9cac65b0b787f782
|
|
| BLAKE2b-256 |
0267d74f486bf81d24e67b349f22b7dc65740a81e1f8d09cc2e7147134dd7ffe
|
File details
Details for the file pykatex-0.1.0-cp313-cp313-macosx_10_13_universal2.whl.
File metadata
- Download URL: pykatex-0.1.0-cp313-cp313-macosx_10_13_universal2.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.13, macOS 10.13+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b8ccfba3025cce83611edf2b3867cbdc4562dd509c69b8dd123a7e0ca1a5bc9
|
|
| MD5 |
4479e472ceb6bd83cd5739fade711374
|
|
| BLAKE2b-256 |
8280036eedd37c941f82cd7d2d9839e727cd3723b6989545097350bf19e938b3
|
File details
Details for the file pykatex-0.1.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: pykatex-0.1.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3001015f37cbc76da24314766ba5ee4470544884d2837e0a6a53a4e67407561
|
|
| MD5 |
9a7275d3313534b9de9a0ed3b2b46d89
|
|
| BLAKE2b-256 |
2ebe9a6956bd4d5f8c95b9cfa63b7271726b3e27c1f2c2dcc7dfc6856b3508d1
|
File details
Details for the file pykatex-0.1.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pykatex-0.1.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f70f320d1b7af5fe89f277ed5ad943e593cb812e0247d28dfdc909c0a9d37546
|
|
| MD5 |
64099b6f8cc9b02a637be5a30c3a566f
|
|
| BLAKE2b-256 |
ff20fffcbd1b9d37e01211d48e1791dab77a6641fe37f9e018e11e7a93fd7224
|
File details
Details for the file pykatex-0.1.0-cp312-cp312-macosx_10_13_universal2.whl.
File metadata
- Download URL: pykatex-0.1.0-cp312-cp312-macosx_10_13_universal2.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.12, macOS 10.13+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b483d18534a1fb340b300f4d4562ed5b58fc491a4bca3a20a8970d45b8be901e
|
|
| MD5 |
30270a61cd2015b4bd3bfe95379b9473
|
|
| BLAKE2b-256 |
d18bc48390f436d02f54a89f1b931644c52e7b17a16aeac0e1e9b3c72062db91
|
File details
Details for the file pykatex-0.1.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: pykatex-0.1.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
edb04cd72a46489bee4979f93362e950cc0a7f9f1e1c53e71a0afb66bbe0736c
|
|
| MD5 |
a9b92ae3e37a0811c50112b84a8f0379
|
|
| BLAKE2b-256 |
ffd128cb72b91a299588e527afe6ab84fee4d169442d23379a7b8236e95ffca1
|
File details
Details for the file pykatex-0.1.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pykatex-0.1.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9cea4a381969ec41831632ea02efe769d7b5bfd116cfc291244f9bf108bb3a47
|
|
| MD5 |
cd0ea4b14122a2f539b13d96d1bedd5c
|
|
| BLAKE2b-256 |
e09a1327f179f44cfe7b5e44326ac0b6adde28e4b6eb1ac1f36993cfa86c617d
|
File details
Details for the file pykatex-0.1.0-cp311-cp311-macosx_10_9_universal2.whl.
File metadata
- Download URL: pykatex-0.1.0-cp311-cp311-macosx_10_9_universal2.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.11, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e06d57d46a741c21980e19872ba3bc2637b86373464fceff5f60c483d44b153e
|
|
| MD5 |
ecda0e0f4b5613974870a78da3665138
|
|
| BLAKE2b-256 |
518b23f99ada3706daba8e7b2db20fba15e835faf975621fad2c5b5e23aee92e
|
File details
Details for the file pykatex-0.1.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: pykatex-0.1.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6ae6df63f7bf135e3daba068dd7c8339910de9737cdbcc975a0315b23599f2f
|
|
| MD5 |
017a4d62eaf2f72f300e81d966a2fbf0
|
|
| BLAKE2b-256 |
17f07ef8dd2f50fb504b9864fb564fa3727cb5b2940d47eb6ed796537482c9c2
|
File details
Details for the file pykatex-0.1.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pykatex-0.1.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbda78435aeccb3ce14c6e8ed5b9e5272c5578809415d0bf15728feba8518027
|
|
| MD5 |
c9b729968d31c96434923e80579497e8
|
|
| BLAKE2b-256 |
95b42e87e885a125a28bbf6220e9165983d4e37fe5a7197acac31a34df6289e7
|
File details
Details for the file pykatex-0.1.0-cp310-cp310-macosx_10_9_universal2.whl.
File metadata
- Download URL: pykatex-0.1.0-cp310-cp310-macosx_10_9_universal2.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ae1f8e6ab032e6b7b0f9a637eae20bf76b197ef813d8d23a858c252a05ce08a
|
|
| MD5 |
9ee3198c3527765ce86884c4f83efe6a
|
|
| BLAKE2b-256 |
c68928bf8c41e8d118702200810cf80fa68cc11ef9e41863248f67e6ae6f0ba9
|
File details
Details for the file pykatex-0.1.0-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: pykatex-0.1.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28b025f000a890f5f34bec06c2c9ad42a5cf5a59b8b2772a671235c7c925b758
|
|
| MD5 |
8feb0334de73df461c135413bc1de6b3
|
|
| BLAKE2b-256 |
28ff31c70cf2db420928fd5c654c1f535efb7e4442b2f3fcda3403d604f2d20c
|
File details
Details for the file pykatex-0.1.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pykatex-0.1.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81d64f23526fc41df4dadd7593ac11d56177a1a1fcc5fd002b42837e562279d3
|
|
| MD5 |
e65d12854df07e6f56f55cbf1dd78618
|
|
| BLAKE2b-256 |
cdd8cb0e652dac7f18cc67e1c87cc0be42826e5638317804212c14a16222e114
|
File details
Details for the file pykatex-0.1.0-cp39-cp39-macosx_10_9_universal2.whl.
File metadata
- Download URL: pykatex-0.1.0-cp39-cp39-macosx_10_9_universal2.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.9, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ce75f622a9cf40038d94e328d3bbc45b10649f73e4a0e6c3bff442609dc45b0
|
|
| MD5 |
60b49a4185371eb19b008d709c726745
|
|
| BLAKE2b-256 |
29b0ad87c1a9c85d1074437c5b792d73e9d5d11704fa5422bb4e0e7614178457
|