Skip to main content

A Python wrapper for the [KaTeX](https://katex.org/) 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 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.

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

pykatex-0.0.8.tar.gz (1.0 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pykatex-0.0.8-cp313-cp313-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.13Windows x86-64

pykatex-0.0.8-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pykatex-0.0.8-cp313-cp313-macosx_10_13_universal2.whl (2.0 MB view details)

Uploaded CPython 3.13macOS 10.13+ universal2 (ARM64, x86-64)

pykatex-0.0.8-cp312-cp312-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.12Windows x86-64

pykatex-0.0.8-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pykatex-0.0.8-cp312-cp312-macosx_10_13_universal2.whl (2.0 MB view details)

Uploaded CPython 3.12macOS 10.13+ universal2 (ARM64, x86-64)

pykatex-0.0.8-cp311-cp311-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.11Windows x86-64

pykatex-0.0.8-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pykatex-0.0.8-cp311-cp311-macosx_10_9_universal2.whl (2.0 MB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

pykatex-0.0.8-cp310-cp310-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10Windows x86-64

pykatex-0.0.8-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pykatex-0.0.8-cp310-cp310-macosx_10_9_universal2.whl (2.0 MB view details)

Uploaded CPython 3.10macOS 10.9+ universal2 (ARM64, x86-64)

pykatex-0.0.8-cp39-cp39-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.9Windows x86-64

pykatex-0.0.8-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pykatex-0.0.8-cp39-cp39-macosx_10_9_universal2.whl (2.0 MB view details)

Uploaded CPython 3.9macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file pykatex-0.0.8.tar.gz.

File metadata

  • Download URL: pykatex-0.0.8.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

Hashes for pykatex-0.0.8.tar.gz
Algorithm Hash digest
SHA256 13dd60350696e4427b1fa0a0ef31e0daad12241f5519943d412e8513bed7aa46
MD5 5d03b3e282a1b95fa680cc4c38563497
BLAKE2b-256 cdafae1501a0eb9a2ff5ba6c9eb852a3cccab1e47287eed895d14b8342ab2608

See more details on using hashes here.

File details

Details for the file pykatex-0.0.8-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pykatex-0.0.8-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

Hashes for pykatex-0.0.8-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8da04a848080e9dfcf57e44b1bea7a515096d48a8c52819fd8e0e42cde7706eb
MD5 6989533729ea5357dd1bf6fbdd74580f
BLAKE2b-256 0ccac79e68fb35175c4dd2fe432c8dfa3c3479af510c08f6e8233e8a95d9ad27

See more details on using hashes here.

File details

Details for the file pykatex-0.0.8-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pykatex-0.0.8-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cfe2c2df863f288a2e9b7f33012859c7ef15beea91fac688478478c85ab5ff57
MD5 70881550ee76d4d0a484cbe7d7e77e04
BLAKE2b-256 8989af84e427289faa6de1d63386fadd75f5098e12eedab69ca0a95b52a1171b

See more details on using hashes here.

File details

Details for the file pykatex-0.0.8-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for pykatex-0.0.8-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 27e918eef17eb501821457c87c5fa5827d34cf86447697c837138650abbd2af2
MD5 ffb647289d46a57584a82790bca575c2
BLAKE2b-256 9cbf101010500a6a453cafea7f99b3cea4a467c8ac5f5f02c44bc3f9b5adabcc

See more details on using hashes here.

File details

Details for the file pykatex-0.0.8-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pykatex-0.0.8-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

Hashes for pykatex-0.0.8-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0a32a9719d4a98014fd991387c89fa4302735bae1864bf604dfb9acdf096134b
MD5 d70fbcf7f2e82eee4f0c168acd7d0924
BLAKE2b-256 5208e328b83d4e9893c2a4dfa6de2e851c30f112cdb2c3c358338cf6ce27b629

See more details on using hashes here.

File details

Details for the file pykatex-0.0.8-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pykatex-0.0.8-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 51899c07f5259ffc669cf1266d4b72a8c7124713ae51ee7b3965912e074ebe56
MD5 e33924bcebaec0ab2dffef662da32aa8
BLAKE2b-256 47d9e994d9a119b6381b6b3bfce879f54e5593c9cfcfa4a13e37975f04181ae3

See more details on using hashes here.

File details

Details for the file pykatex-0.0.8-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for pykatex-0.0.8-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 76dfe43942b77934db11b4fb7eea4ddd3d17b05cdddbb316e39df95a4f0140c9
MD5 33bc47ab254d7e5d5870362fad63c7b9
BLAKE2b-256 05c23bd6b439f592688a7e4245cab1944c616f1a475b8d5cdf57404dda2937fc

See more details on using hashes here.

File details

Details for the file pykatex-0.0.8-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pykatex-0.0.8-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

Hashes for pykatex-0.0.8-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f529e973f4bced4198b1c0182c7b95e8a055fb63f4251482810fc0ae30dc8402
MD5 519d2a57b1a5b118eb16720fb0259014
BLAKE2b-256 dd7e73232430e4d75088e812467e7fafe3f3e3d333e089457f342c5c6bb5eaf4

See more details on using hashes here.

File details

Details for the file pykatex-0.0.8-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pykatex-0.0.8-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8a71bb7b042c7dc2c3d5bc97c82bbd4e763a464223c998586da7852de8ad61b4
MD5 e8a88141cbbd2d8417bec227dbb756d5
BLAKE2b-256 e9f48d595b4d8c00a4d64b28673327edfa7ed6e6c01aee2a6691b6f4eed29ab8

See more details on using hashes here.

File details

Details for the file pykatex-0.0.8-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for pykatex-0.0.8-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 0c1517ce6d22603fb9c3a1abcf9cc558d8eb2c6097439d74a9091ffa31604bd0
MD5 00e7864a8513e7d2f6df5958c883f11a
BLAKE2b-256 471cf77e63e2a17a2cf344d04d6e0633ad1951ff8f8dde2d4130824eaa630b2d

See more details on using hashes here.

File details

Details for the file pykatex-0.0.8-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pykatex-0.0.8-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

Hashes for pykatex-0.0.8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 57c438f43528d503ec91d3b5df4db8482bacb37946e6edcc4598f3111ad2bf7e
MD5 e6eeb77bd434fc5897cf7ba9d08293fb
BLAKE2b-256 ab773f606fccb1f89a77ac1dd0006e55cbbe948f62cdb3a96360a66ab72e42c8

See more details on using hashes here.

File details

Details for the file pykatex-0.0.8-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pykatex-0.0.8-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ac3227c96f59b5b213974c57c7aef77fb8abef6e1a56ec0220b8de6be3e6dcf9
MD5 b0770c1021f9a0e1eecd2131bbf8cc59
BLAKE2b-256 ce7c6b7197512ae0f5c49e38f62e68b80d134390a87b25393942f4ecb74f7d5f

See more details on using hashes here.

File details

Details for the file pykatex-0.0.8-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for pykatex-0.0.8-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 adb06db3ce1c40e6433ecf60b7b01f830e0c93f7685590c932740d9157c39337
MD5 9bfdeac11cfe2a0b88b57f5c5d926db1
BLAKE2b-256 b36af537d85d46f139b34bcaf2b5c5fc2e7584c65a30fa24d1bc5160bff1abfc

See more details on using hashes here.

File details

Details for the file pykatex-0.0.8-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pykatex-0.0.8-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

Hashes for pykatex-0.0.8-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a7f4df2dbe3b17e8cb16742445f982cd214f2c9a6646b126b66c3d066a173038
MD5 f5ef29f11e8a453c26a00226421cdeca
BLAKE2b-256 aeabee91fc8ab0be96ccec72181e2151eba724f6632bd25e636a7f04027059a2

See more details on using hashes here.

File details

Details for the file pykatex-0.0.8-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pykatex-0.0.8-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 010ede00725c8ab5f1997aee370301bc44483d5159d9df1416f46ddc33eb09be
MD5 1c8dcd6cdb4c7965db3c64c52debd6fb
BLAKE2b-256 d46d19a1ad88f163642f1a9e5822cdb281e5d7ba4099839a9a3d7bc077b73b83

See more details on using hashes here.

File details

Details for the file pykatex-0.0.8-cp39-cp39-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for pykatex-0.0.8-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 6985e53e8ec0175b3597b7972917d9f7ee71d168c5b9dc81381dab1737652ce4
MD5 ba8e702b7224122bfc3ede44c76f7d34
BLAKE2b-256 3d6503827137bb1e6e0af0f4a4c5fb566179f43ca739c952ab4a962726ab872f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page