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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytex_preprocessor-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 12c8b942924b6c8a3dece59b1b24326dfad4b70547c251eb749a0a3f55d6db29
MD5 a1803cdf15fd9f3a96cd20a3eeccb423
BLAKE2b-256 3316a5d86048bb181aacca2c2a8b7abd258ec9e1a97f9943a1f4310ba83e3311

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytex_preprocessor-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e48cdbbc5c4c149e0dc60c283e088bc6406c96f25eb7187b691020a526dc1664
MD5 dedf114db07727a427853512008c00e4
BLAKE2b-256 07c4c683fe9c0641e72f2ee2e13b62661c54d72f4df64918920d3eaa5849ffb6

See more details on using hashes here.

Provenance

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