Skip to main content

Type-safe LaTeX document generation with Python

Project description

pytex

Install

python -m venv venv && . venv/bin/activate
pip install -e .            # add [dev] for pytest

SVG conversion needs inkscape. Compiling to PDF needs tectonic — if it is not on PATH, pytex --build downloads a self-contained binary into a temp folder and reuses it on later runs. Resolving glossaries/acronyms needs makeindex from a TeX distribution (e.g. TeX Live).

The pytex command

pytex example.tex.py          # render -> example.out.tex
pytex example.tex.py --build  # render + compile -> build/example.out.pdf

The input is either:

  • a .py file exposing a module-level __pytex__ variable that is a TeX node (e.g. a Document) — it is rendered, or
  • a .tex file — wrapped in IncludeTeX (so \iffalse pytex(...) \fi replacements are evaluated) and rendered.

Options

Flag Default Meaning
-o, --output <input>.out.tex rendered LaTeX output path
-b, --build off compile the rendered .tex to PDF with tectonic
--build-dir DIR build directory for artifacts and tectonic output
--no-shell-escape shell-escape on disable shell-escape

Shell-escape is enabled by default because inline images decode their base64 payloads at compile time. The build runs tectonic, then makeindex (for glossaries/acronyms), then reruns tectonic when an index changed.

Output is minimal and color-tagged (==>, note:, warning:, error:), following tectonic's style; on failure it points at the likely cause and the log file. Set NO_COLOR to disable color.

Markdown

pytex_markdown converts Markdown to native TeX nodes (via marko):

from pytex_markdown import Markdown, IncludeMarkdown

body = Markdown("# Title\n\nText with **bold**, `code`, [a link](https://x).")
body = IncludeMarkdown("notes.md", base_level=-1)   # base_level=-1: # -> \chapter

Headings, emphasis, inline/fenced code, lists, links, images, block quotes and thematic breaks map to the standard pytex library; text is LaTeX-escaped. GitHub-style callouts become HSRT colored boxes (so the module depends on pytex_hsrtreport):

> [!NOTE]      -> InfoBox        > [!IMPORTANT] -> ImportantBox
> [!TIP]       -> SuccessBox     > [!WARNING]   -> WarningBox

Both factories are registered, so they are usable from \iffalse pytex(...) \fi replacements in .tex sources too.

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

pytex_preprocessor-0.1.0.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

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

pytex_preprocessor-0.1.0-py3-none-any.whl (1.1 MB view details)

Uploaded Python 3

File details

Details for the file pytex_preprocessor-0.1.0.tar.gz.

File metadata

  • Download URL: pytex_preprocessor-0.1.0.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pytex_preprocessor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cf1f9a10335abf3e1136d953093cc6e13b0ab8a1c36a974d62274f19f25c857b
MD5 16e683245a6afe83d9b57da79744b522
BLAKE2b-256 e3b00699893d06da322533e10d5c42a370a357ee0f95b1e33e919c6ae5f4516e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytex_preprocessor-0.1.0.tar.gz:

Publisher: release.yml on frederikbeimgraben/PyTeX-Preprocessor

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

File details

Details for the file pytex_preprocessor-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytex_preprocessor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c9ff07d2bc1be98ccf09a477728ae2beb6a80eae60697a34ade279b79c1708e
MD5 bbf582b640fd35936194bb878bb847e4
BLAKE2b-256 3cc184f5f4b7e026b26fb10c7d1a86ba41dba2d873bec6a3797b4daec9b0cd92

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytex_preprocessor-0.1.0-py3-none-any.whl:

Publisher: release.yml on frederikbeimgraben/PyTeX-Preprocessor

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