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.2.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.2-py3-none-any.whl (1.1 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytex_preprocessor-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 7b7a1cc829facefa32b28f8641c1f43ff27f967a870cd0be4d151a572250436a
MD5 1547c3ded6eb387bed3fe1c422644019
BLAKE2b-256 b3f83d62880bb343e06470de7049a78552dc30ff97d531cfd3e223a9af336e95

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytex_preprocessor-0.1.2.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.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pytex_preprocessor-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f585b13e4bb097933aac739e0e1be1c8539c3074815cefcb1d900ab674960189
MD5 5c946ca8181317ddc227a0c1bebd7029
BLAKE2b-256 5d769bb1b4c61439978a33484ccc3efbc70be78992a661648cc15afa7063a1c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytex_preprocessor-0.1.2-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