Skip to main content

A simple python library for converting latex snippets to images.

Project description

tex2image

Documentation Status PyPI Version

This is a simple library to generate images from tex snippets.

It uses the standalone latex package to produce PDFs that are already set to an appropriate size, and then uses poppler to convert the PDF to an image. You must make sure that pdflatex (available from TeX Live) and pdftoppm (available in many package managers, and usually distributed as part of poppler-utils) are available for python to execute.

Quick start

Direct usage

Once you have installed pdflatex and pdftoppm, you can use the library like so:

from pathlib import Path
from tempfile import TemporaryDirectory

from tex2image import latex_to_png

with TemporaryDirectory() as temp_dir:
    image_file_path = latex_to_png("Pythagorean Theorem: $a^2 + b^2 = c^2$.", Path(temp_dir))
    # Do something with the image here, before temp_dir gets deleted...

Client / server method

If you would like to install the pdflatex and pdftoppm dependencies in a container, then you may wish to use the simple FastAPI server included in this library. To launch the server, run

pip install tex2image[server]
tex2image-server
# Or run `tex2image-server --help` to see available options.

Alternatively, this library distributes an official Docker image:

docker run --rm -it ghcr.io/olympiad-bot/tex2image

Both methods will serve a FastAPI server: navigate to [host]:[port]/docs (localhost:8000/docs by default) for OpenAPI documentation for the server.

The server can be easily interacted with from python by using the tex2image.client module. For example:

from tex2image import TexRenderingClient

c = TexRenderingClient()
image_bytes = c.latex_to_png("Pythagorean Theorem: $a^2 + b^2 = c^2$.")

For some more useful examples, see the examples folder; in particular, for examples of using the client, see the Discord bot example and the Flask app example.

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

tex2image-1.0.0.tar.gz (351.3 kB view details)

Uploaded Source

Built Distribution

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

tex2image-1.0.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file tex2image-1.0.0.tar.gz.

File metadata

  • Download URL: tex2image-1.0.0.tar.gz
  • Upload date:
  • Size: 351.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.12 {"installer":{"name":"uv","version":"0.11.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tex2image-1.0.0.tar.gz
Algorithm Hash digest
SHA256 881bb42679f63b5cc40442c4b917c664b9364d6134dcbe4186f580a57b708c88
MD5 0cf667228241457998f7307eef44a814
BLAKE2b-256 11da4afdb522bfa9410c3ad6caf3aff86511844f3631002ce80afbd2a7d92917

See more details on using hashes here.

File details

Details for the file tex2image-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: tex2image-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.12 {"installer":{"name":"uv","version":"0.11.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tex2image-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1cfa2d397444ffd73311be2385fabf29730ae1588164a5b06477d4625bc341e2
MD5 91bc9c86dddd32d231cf9c7931ad4d8a
BLAKE2b-256 dc52c58a784edef8888b1029c68133a40ef8148cad48a9193f3978e83d802a42

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