PYPI PACKAGE AUDIT v2.4.1 Needs Improvement

retex

Compile LaTeX documents to PDF, SVG, ODT, HTML and Markdown from Python, with retex, a LuaLaTeX-compatible TeX engine in Rust

PyPkgScore retex
Methodology & Criteria ♥ Donate
540 / 1000
Quick Install
pip install retex
1. Governance
0/200
2. PEP Metadata
200/200
3. Security
150/200
4. Docs & SEO
155/200
5. CI Engineering
35/200
📣 Share Audit: Share this report and visual preview in the current language
Advertisement
PYPI TELEMETRY

Downloads & Community Adoption

Last 30 days (without mirrors)
Last 7 days
395
Last 30 days
879
Total (180 days)
879
Metric / Ecosystem Status / Value Source
Downloads (30d / 180d) — PyPI Stats (without mirrors)
Trusted Publishing (PEP 740) ✕ Not detected PyPI Integrity / Sigstore
Django Packages — djangopackages.org
PyTech / PyPkgScore 540 / 1000 PyPkgScore Engine

Health & Engineering Analysis (5 Pillars)

1. Governance & Community0 / 200 ▾
LICENSE✕ 0 pts
SECURITY.md✕ 0 pts
CONTRIBUTING.md✕ 0 pts
CODE_OF_CONDUCT.md✕ 0 pts
2. PEP Metadata & Packaging200 / 200 ▾
Wheel (.whl)✓ 50 pts
pyproject.toml✓ 50 pts
Project URLs✓ 50 pts
Trove Classifiers✓ 50 pts
3. Security & Supply Chain150 / 200 ▾
Zero CVEs (OSV)✓ 60 pts
Trusted Publishing (OIDC)✕ 0 pts
Snyk / Audit Link✓ 40 pts
HTTPS Repository✓ 50 pts
4. Documentation, SEO & Ecosystem155 / 200 ▾
Structured README✓ 60 pts
Read the Docs✓ 50 pts
Django Packages✕ 0 pts
Website / Technical Articles✓ 45 pts
5. Engineering, CI & Quality35 / 200 ▾
Automated Tests✕ 0 pts
GitHub Actions CI✕ 0 pts
CHANGELOG.md✓ 35 pts
Env & Lockfile (uv/rye/poetry/pdm/hatch)✕ 0 pts
Advertisement
README & DOCS

Official Documentation & Usage Guide — retex

PyPI Metadata v2.4.1
Show full original documentation (English README) ▾

retex for Python

Compile LaTeX documents from Python, to PDF, SVG, ODT, ODP, HTML and Markdown, with retex, a TeX engine written in Rust whose output is pixel-identical to LuaLaTeX's. retex runs in the Python process and starts no TeX program.

import retex

tex = retex.Retex()
doc = tex(r"""
\documentclass{article}
\begin{document}
Hello, \LaTeX{} from Python! $e^{i\pi} + 1 = 0$
\end{document}
""")

pdf = doc.to_pdf()        # bytes
svg = doc.to_svg()        # str: every page, stacked
odt = doc.to_odt()        # bytes
docx = doc.to_docx()      # bytes (experimental)
pptx = doc.to_pptx()      # bytes (experimental; a beamer deck's slides)
html = doc.to_html()      # str: one file, fonts and pictures in it
md = doc.to_markdown()    # str
doc.save("hello.pdf")     # or .svg, .odt, .odp, .html, .md, .docx, .pptx

A build runs every pass the document needs, BibTeX, biber and makeindex included. What it reported is in doc.diagnostics, doc.errors and doc.warnings. A build that writes no output raises retex.RetexError, whose diagnostics and log say why. In Jupyter, a document shows as its pages (an SVG image; front ends that take PNG images show the first page at 96 dpi).

Pages as images, drawn in the process (from the page's SVG, with resvg):

png = doc.to_png()                 # bytes: the first page at 150 dpi
a = doc.to_numpy(page=0, dpi=300)  # numpy array, uint8, (height, width, 3)
a = doc.to_numpy(alpha=True)       # (height, width, 4), transparent background
pages = doc.to_numpy(page=None)    # a list, one array per page
im = doc.to_pil(crop=True)         # a PIL image, cut down to the ink

Pages are numbered from 0 (negative numbers count from the end). crop=True keeps what the page paints, with a margin of 2 points. For a formula, use \pagestyle{empty} or the standalone class so that the page number is not part of it. numpy and Pillow are needed only by to_numpy and to_pil.

Options, all keyword arguments of Retex:

option meaning
passes at most this many passes (default 5; 1 runs TeX once)
shell_escape let \write18 run programs (default False)
accessible tagged PDF, checked for accessibility (PDF/UA-2)
working_dir where the document's own files (pictures, .bib) are
job_name the job name (default document)
files {name: str or bytes}: files the document reads
keep_files keep the build's files (log, .aux) in this directory

Retex.compile_file(path) compiles a .tex file, its directory being the working directory.

retex needs a TeX Live installation (2025 or 2026) for the LaTeX packages and fonts. Builds release the GIL. They run one at a time in a process, and change the current directory while they run.

Build the wheel with maturin: maturin build --release in this directory. cargo xtask python builds it and runs tests/. For PyPI, build a manylinux wheel with maturin build --release --zig --compatibility manylinux_2_28 (with zig on PATH).

Examples

The scripts are in examples/.

A formula in a matplotlib figure, typeset by LaTeX (amsmath, any package) rather than by mathtext:

formula = retex.compile(r"""\documentclass{standalone}
\begin{document}$\displaystyle \varphi(x) = \frac{1}{\sqrt{2\pi}}\, e^{-x^2/2}$
\end{document}""").to_numpy(dpi=300, alpha=True, crop=True)
ax.add_artist(AnnotationBbox(OffsetImage(formula, zoom=fig.dpi / 300),
                             (-2.6, 0.3), frameon=False))

One PDF per person: a template filled in and compiled in a loop (certificates, letters, badges). A Retex keeps its options from one build to the next:

tex = retex.Retex(passes=2)
for name in ["Ada Lovelace", "Alan Turing", "Grace Hopper"]:
    tex(TEMPLATE.replace("@NAME@", name)).save(f"certificate-{name.split()[-1]}.pdf")

A contact sheet: every page of a document as a thumbnail, in one image:

pages = retex.Retex().compile_file("thesis.tex").to_pil(page=None, dpi=24)
w, h = pages[0].size
sheet = Image.new("RGB", (8 * w, rows * h), "white")
for i, page in enumerate(pages):
    sheet.paste(page, ((i % 8) * w, (i // 8) * h))

A check for continuous integration: build every document and print its errors, with their file and line, as the retex program does:

tex = retex.Retex()
for path in pathlib.Path("docs").rglob("*.tex"):
    try:
        problems = tex.compile_file(path).errors
    except retex.RetexError as e:
        problems = e.diagnostics
    for d in problems:
        print(d)   # docs/intro.tex:12: error: undefined command \sectoin

An animated GIF: numpy computes the curves, TikZ draws them, one tikzpicture a frame. With the standalone class's tikz option each picture is a page, and page=None gives every page as an image:

a = np.linspace(0, 2 * np.pi, 300)
pictures = []
for degrees in range(0, 360, 5):
    t = np.radians(degrees)
    x, y = 2 * np.sin(3 * a + t), 2 * np.sin(2 * a)
    path = " -- ".join(f"({u:.3f},{v:.3f})" for u, v in zip(x, y))
    pictures.append(rf"\begin{{tikzpicture}} ... \draw {path}; \end{{tikzpicture}}")
doc = retex.compile(r"\documentclass[tikz]{standalone}\begin{document}"
                    + "\n".join(pictures) + r"\end{document}")
frames = doc.to_pil(page=None, dpi=72)
frames[0].save("lissajous.gif", save_all=True, append_images=frames[1:], duration=60, loop=0)

Lissajous curves, a ribbon of colours, turning: an animated GIF

TeX to pixels and back: a glyph drawn as an array, then redrawn as a TikZ picture of dots, one for each cell, as large as the cell is dark (a vector halftone):

ink = 1 - retex.compile(GLYPH).to_numpy(dpi=40).mean(axis=2) / 255
dots = [rf"\fill ({c},{-r}) circle ({0.55 * ink[r, c]**0.5:.3f});" for r, c in cells]
retex.compile(TIKZ_HEAD + "\n".join(dots) + TIKZ_TAIL).save("halftone.pdf")

An italic ampersand redrawn as coloured TikZ dots