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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytex_preprocessor-0.1.0rc1.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.0rc1.tar.gz
Algorithm Hash digest
SHA256 96abc26669fea56dc58e142fceeeedc4ed88692a205fd5b2809138e898fe1735
MD5 fa7a59f4fe35bf2aca1c3a4abeaf9d31
BLAKE2b-256 b4f1034c9fe5db45b3069f40521071c2d386bbbb9d03611ca3790858d4af811b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytex_preprocessor-0.1.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 7fb484b183764d1fa6355f1ed7d967217a5659c59230a70c7679db47b66ac9cb
MD5 9813bf7b185bbe08ed29927e9b2e5989
BLAKE2b-256 e46dd48983ea745d444fe94a2f773a728e8488e98a12883f5f240379e433a533

See more details on using hashes here.

Provenance

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