Skip to main content

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 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.1.1.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.1.1-cp313-cp313-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.13Windows x86-64

pykatex-0.1.1-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.1.1-cp313-cp313-macosx_10_13_universal2.whl (2.0 MB view details)

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

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

Uploaded CPython 3.12Windows x86-64

pykatex-0.1.1-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.1.1-cp312-cp312-macosx_10_13_universal2.whl (2.0 MB view details)

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

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

Uploaded CPython 3.11Windows x86-64

pykatex-0.1.1-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.1.1-cp311-cp311-macosx_10_9_universal2.whl (2.0 MB view details)

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

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

Uploaded CPython 3.10Windows x86-64

pykatex-0.1.1-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.1.1-cp310-cp310-macosx_10_9_universal2.whl (2.0 MB view details)

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

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

Uploaded CPython 3.9Windows x86-64

pykatex-0.1.1-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.1.1-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.1.1.tar.gz.

File metadata

  • Download URL: pykatex-0.1.1.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.1.1.tar.gz
Algorithm Hash digest
SHA256 22809068e7e1f41a50a3475805adf0bfea4893245f1dac9699d426fa06a2b165
MD5 5a9cd2133187030ee82581e74fce7b8f
BLAKE2b-256 61d99617bd5f716908115943a9b2aff95df59d9ec032f5fd886fcab0657a11c7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pykatex-0.1.1-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.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 fa75f3dd2853e0a51a454445880d6def1ac328bdb324761eaea954f39a2b9b30
MD5 49091299b114ca7155189a8c3d2df26e
BLAKE2b-256 ce543f0e3c1ca99e431716e474d0ab1e18a947695fd09066c9673a69dfe86e92

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pykatex-0.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 568c2a0951a03460dca44f9289824ac6f9e3ded777267efd30ff69c8da209e99
MD5 c9f9306213c4fb8f91b51c57c7e48937
BLAKE2b-256 c6174e9216ec7fb5b4f4e95dcfa8b932d5b683344b2260a3f54233d3447b8069

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pykatex-0.1.1-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 bb803bc28bbe0f3bdb3ebb7343a22d4b79b0d6801692934eacc9465f2a094196
MD5 6400dba13b0b52e1f94de2df202458d0
BLAKE2b-256 b224d3b5f2012a09ce320ab49146f2b0a7656aa11ae56db4ae70fc074cdade36

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pykatex-0.1.1-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.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 222d9c02b273530f21933e4425ffe525788a67f33a280be942dead1674d7a76f
MD5 1907ac90fa2dc16911b99fb8f7261f1e
BLAKE2b-256 195b4d907b5f3ca1e4ca24a01ce76d5efa80974d13701c02e5de881a601d74b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pykatex-0.1.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 41bbfdd6fc09362a4d7758b36497c077f5b779a25bba2e375d653f807427a873
MD5 a259a06d94364fb3203b2f0d1121f80f
BLAKE2b-256 97f29173af3b50bc4c2c7c00d39f69deb4513a89ab2d4f1a7ca1276a933fe7eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pykatex-0.1.1-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 72a874c4703a5f3f14845ac723b4327f4206cee695076286996b264c48554c57
MD5 72354fcd0f84548ad0524ec90fe8ca27
BLAKE2b-256 c59c4d8a8235e7ee6da137a76bbde6d9d025e31b32b447148d51f17abd6b5979

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pykatex-0.1.1-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.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ff5c6c9202fa6ed8e22b80928ba2903e87bc43f0351c4fc15495b28fc9036a13
MD5 5591caf34d3b27581fbde0ae7975eae7
BLAKE2b-256 a025b3d41dd9160a6bb59e12d9042ec76a5aa3f81ed4c33ec81c3393d61c0895

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pykatex-0.1.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 92052672af7166a6fd0fae03a8b8f650e6c3163a2830f2045ac53a1feacd8286
MD5 a8d0257cd5103273a40a8ac85d237577
BLAKE2b-256 98dca715cbd1914b3bf5d993fc67c5f244af5d689c9faeba6eb446556b85fbe6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pykatex-0.1.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 03cd071ab3f25f7d7c37ee410fd278d81b1c5a4f3804e911ab09474cc7560eab
MD5 e2483243663e68e22e2dd39d8dbd870e
BLAKE2b-256 19926477398807eb188ed0f57b427451be3c6ad84c99ba091c91b6a78d262a69

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pykatex-0.1.1-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.1.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ba2920c077f49c2f207b2c620d8f84de3d855907466ff77555d4ca8befe9f711
MD5 9b28dd14817bd7aca4151b648f834fd6
BLAKE2b-256 45b0027cada76cf348dcd997461887f1e6d51e1aa8d221c063b16628cd3c7fdd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pykatex-0.1.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2a573820d8ca792336404aef81c030d26e71c653f347f7cad3fb8337d8e1dcb8
MD5 37d94b5151ef2d3db49f5edb98e82e8f
BLAKE2b-256 686422589256e93e395ecb30602472ea49514b5aae5c8c2c17c508ff73a66a4b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pykatex-0.1.1-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 b86d90ce018a804dc8dbba14ee69af415de81493dfc196cbbce1489bcb26c13c
MD5 12fa4e7f8c4436482a7ffbe0ecadb1ef
BLAKE2b-256 b7667bf3dedffc33aee3900a800bf7e4a3e2f759569d99d03887ae26d641f2ad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pykatex-0.1.1-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.1.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 cbc68206655e440424d0cdfea89f95bc1e84fd7894a831ad5f784f7c5ece492d
MD5 72829104283cb1b9067090224bacce8b
BLAKE2b-256 a08345f62a56c087aa6b709c2c3628d77d1cf8448ceb149553675c9a0e1a7ab9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pykatex-0.1.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3d8cf8d2bf31676109d7a5174fe89ca7f2648f4b26d6624c276ae5388fc7910e
MD5 8437f911a4fe72a07d63a6ab27a93fd6
BLAKE2b-256 11f3cb65e314818b6a4535bc629b05b6834a63d60250e797335845c0374f392e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pykatex-0.1.1-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 3bfeac8649aef883200017632d1e688be3da09d7c22a8d8476922ffffade96dd
MD5 cbba1e61d95ae3e76123f85e387ece32
BLAKE2b-256 021dadfd552006885805157c1c66f4f3ecad4859084bc413ada644275e82b473

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