PreTeXt CLI

raw JSON →
2.38.3 verified Sat May 09 auth: no python

A Python package for authoring, building, and deploying PreTeXt projects. PreTeXt is an XML-based markup language for writing academic articles, textbooks, and other documents. Current version 2.38.3, requires Python >=3.10, <4.0. Roughly monthly releases.

pip install pretext
error ModuleNotFoundError: No module named 'pretext'
cause Package not installed or typo in import (capital P instead of lowercase).
fix
Install with pip install pretext and ensure import is import pretext (all lowercase).
error ImportError: cannot import name 'PretextProject' from 'pretext'
cause Using older version of pretext (pre-2.0) that did not have PretextProject class.
fix
Upgrade pretext with pip install --upgrade pretext.
breaking Python 3.10+ required. Installation on Python 3.9 or older will fail.
fix Upgrade to Python >=3.10.
gotcha Importing submodules (e.g., `pretext.build`) directly is discouraged; use `pretext.build(project_dir, format=...)` via the top-level API. Direct imports may break without notice.
fix Always import from the top-level `pretext` package. E.g., import `pretext` and call `pretext.build(...)`.

Create a new PreTeXt project and build to HTML.

from pretext import PretextProject

# Create a new project in the current directory
project = PretextProject()
project.setup("my-book", author="Your Name", source_dir="source")
print(f"Project created at {project.path}")

# Build to HTML
from pretext import build
def build_html(project_dir):
    build(project_dir, format="html")
    print("Build complete")

build_html("./my-book")