Skip to main content

Thin wrapper for "TinyTeX" (MIT)

Project description

PyTinyTeX

Build Status PyPI version Development Status Python version License

The easiest way to go from .tex to .pdf in Python. PyTinyTeX wraps TinyTeX — a lightweight, cross-platform, portable LaTeX distribution based on TeX Live — and gives you compilation, package management, and diagnostics from Python or the command line.

import pytinytex

pytinytex.download_tinytex()
result = pytinytex.compile("paper.tex", auto_install=True)
print(result.pdf_path)  # paper.pdf

No system-wide TeX installation required. Missing packages are installed automatically.


Installation

pip install pytinytex

Python 3.8+ on Linux, macOS, and Windows.

Quick start

1. Get TinyTeX

import pytinytex

# Download the default variation (variation 1: ~90 common LaTeX packages)
pytinytex.download_tinytex()

# Or pick a variation:
#   0 — infrastructure only, no packages
#   1 — common packages (default)
#   2 — extended package set
pytinytex.download_tinytex(variation=2)

# Track download progress
pytinytex.download_tinytex(progress_callback=lambda downloaded, total: print(f"{downloaded}/{total} bytes"))

2. Compile a document

result = pytinytex.compile("paper.tex")

if result.success:
    print("PDF at:", result.pdf_path)
else:
    for error in result.errors:
        print(f"  ! {error.message} (line {error.line})")

Multi-pass compilation for cross-references and TOC:

result = pytinytex.compile("paper.tex", num_runs=2)

Choose your engine:

result = pytinytex.compile("paper.tex", engine="xelatex")
result = pytinytex.compile("paper.tex", engine="lualatex")

3. Auto-install missing packages

The killer feature: if your document needs a package you don't have, PyTinyTeX can find it, install it, and retry — all in one call:

result = pytinytex.compile("paper.tex", auto_install=True)
print(result.installed_packages)  # e.g. ['booktabs', 'pgf']

Package management

Full access to the TeX Live package manager (tlmgr):

import pytinytex

pytinytex.install("booktabs")
pytinytex.remove("booktabs")

# List installed packages (returns list of dicts)
for pkg in pytinytex.list_installed():
    print(pkg["name"])

# Search for packages
pytinytex.search("amsmath")

# Detailed package info (returns dict)
pytinytex.info("booktabs")

# Update all packages
pytinytex.update()

# TeX Live version
pytinytex.get_version()

Engine discovery

Locate LaTeX engine executables (variation 1+):

pytinytex.get_engine("pdflatex")   # full path to the executable
pytinytex.get_engine("xelatex")
pytinytex.get_engine("lualatex")

# Convenience shortcuts
pytinytex.get_pdflatex_engine()
pytinytex.get_xelatex_engine()
pytinytex.get_lualatex_engine()

LaTeX log parser

Parse any LaTeX .log file into structured data — useful even outside PyTinyTeX:

from pytinytex import parse_log

with open("paper.log") as f:
    parsed = parse_log(f.read())

for error in parsed.errors:
    print(f"{error.file}:{error.line}: {error.message}")

for warning in parsed.warnings:
    print(warning.message)

# Missing .sty packages detected automatically
print(parsed.missing_packages)  # e.g. ['tikz', 'booktabs']

Health check

Diagnose your TinyTeX installation:

result = pytinytex.doctor()
for check in result.checks:
    status = "PASS" if check.passed else "FAIL"
    print(f"  [{status}] {check.name}: {check.message}")

Checks: TinyTeX installed, PATH configured, tlmgr functional, engine availability.

Command-line interface

Every feature is also available from the terminal:

# Download TinyTeX
pytinytex download
pytinytex download --variation 2

# Compile a document
pytinytex compile paper.tex
pytinytex compile paper.tex --engine xelatex --runs 2 --auto-install

# Package management
pytinytex install booktabs
pytinytex remove booktabs
pytinytex list
pytinytex search amsmath
pytinytex info booktabs
pytinytex update

# Diagnostics
pytinytex doctor
pytinytex version

# Also works as a Python module
python -m pytinytex doctor

Integrating with pypandoc

PyTinyTeX pairs naturally with pypandoc for converting Markdown, HTML, and other formats to PDF:

import pytinytex
import pypandoc

pdflatex_path = pytinytex.get_pdflatex_engine()
pypandoc.convert_file("input.md", "pdf", outputfile="output.pdf",
                      extra_args=["--pdf-engine", pdflatex_path])

Uninstalling TinyTeX

pytinytex.uninstall()  # removes the TinyTeX directory

Or from the CLI:

pytinytex uninstall

Contributing

Contributions are welcome. When opening a PR, please keep the following guidelines in mind:

  1. Before implementing, please open an issue for discussion.
  2. Make sure you have tests for the new logic.
  3. Add yourself to contributors in this README unless you are already there.

Contributors

License

PyTinyTeX is available under the MIT license. See LICENSE for more details. TinyTeX itself is available under the GPL-2 license.

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

pytinytex-0.5.1.tar.gz (33.2 kB view details)

Uploaded Source

Built Distribution

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

pytinytex-0.5.1-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file pytinytex-0.5.1.tar.gz.

File metadata

  • Download URL: pytinytex-0.5.1.tar.gz
  • Upload date:
  • Size: 33.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytinytex-0.5.1.tar.gz
Algorithm Hash digest
SHA256 206d2adcbe58262ee501399c7aed30b684473b03dcb71fc248271d1801138525
MD5 99556f89cf65bee3c10cadc91a01e7bb
BLAKE2b-256 7c9cdfbe60d3f33b3406fb9a50d06d9f1ad086e24d1bc83d6fdd992e12d02eb6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytinytex-0.5.1.tar.gz:

Publisher: ci.yaml on JessicaTegner/PyTinyTeX

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytinytex-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: pytinytex-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytinytex-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 16cbad3f70e40a14855bbd807bab9ba74232e87268738dc4ce2af4f6abd6d248
MD5 1f7b834897fcd812009dd3e3a7a658fa
BLAKE2b-256 76ae169877f749443356ac9f5ff07dc128fdead4ccd4094ba3ad9bc5ee53d2a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytinytex-0.5.1-py3-none-any.whl:

Publisher: ci.yaml on JessicaTegner/PyTinyTeX

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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