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.0.tar.gz (32.9 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.0-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytinytex-0.5.0.tar.gz
  • Upload date:
  • Size: 32.9 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.0.tar.gz
Algorithm Hash digest
SHA256 5dca1e69136585944ef31569c401d19d854f8cd6adee8b01eccdc6f60a543edf
MD5 c155182526a3edb5c3d0eb6d04b2fe3e
BLAKE2b-256 e26234172f85255cb8ffdc5cf12203ef6689e9f38d582498eb3fdd45ebb7e588

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytinytex-0.5.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: pytinytex-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 20.5 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 98ac467aebbeac18cbd5e9c67d3f4500e4d788f23c2ca44f749e1bb8a2ed97f2
MD5 ee410f9d3f23cfa17a196727d6010b72
BLAKE2b-256 6f23952bd663bcdcd2a7ef7b1f9576e2a69d910acdbb868a40849012a9721ec4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytinytex-0.5.0-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