Skip to main content

TeXSmith

CI Coverage PyPI Repo Size Python Versions License

MkDocs MkDocs Material Python

TeXSmith is a Python package and CLI tool to convert Markdown or HTML documents into LaTeX or Typst. It is designed to be extensible via templates and integrates with MkDocs for generating printable documents from documentation sites.

TL;DR

pip install texsmith
texsmith input.md input.bib -o build/ --build

Check the installed version with texsmith --version or in Python with texsmith.get_version().

Key features

  • MkDocs-native Markdown – Ships with the same Material + pymdown extension stack you use in MkDocs, so tabs, callouts, annotations, tooltips, and data tables survive the conversion.
  • Typed IR with multiple backends – Documents are lowered into a typed intermediate representation (read(HTML) → IR → write(IR)), then emitted as LaTeX (default) or Typst (experimental) via --format.
  • Template-first runtime – Bundle multiple fragments into slots, merge front matter metadata, and emit LaTeX projects ready for Tectonic or latexmk with Docker-friendly manifests.
  • CLI and Python parity – The Typer-powered CLI wraps the same ConversionService you can consume as a library, making CI/CD and notebooks behave like local runs.
  • Actionable diagnostics – Structured emitters, verbosity switches, and --debug traces keep build issues debuggable even in automated pipelines.
  • Extensible converters – Override Markdown parsers, add reader lowerings (@reads) and writer emitters (@writes), or ship diagram transformers (Mermaid, Draw.io, Svgbob) that plug directly into the pipeline.

Installation

# uv (recommended for isolated CLI installs)
uv tool install texsmith

# pip / pipx
pip install texsmith
pipx install texsmith

TeXSmith targets Python 3.10+ and expects a LaTeX distribution (TeX Live, MiKTeX, or MacTeX) when you pass --build with the default LaTeX backend. Optional converters such as Mermaid rely on Docker (minlag/mermaid-cli) unless you register custom handlers.

To build with the Typst backend (--format typst), install the embedded compiler as an extra:

pip install "texsmith[typst]"
# or with uv
uv tool install "texsmith[typst]"

This bundles the typst PyPI package, so no system binary is required. A system typst on PATH (Homebrew, cargo install typst-cli, or a GitHub release) is detected automatically as a fallback. See the Output backends guide for details.

Platform notes

  • Linux – Install TeX Live (full) via your package manager or install-tl. When running inside CI containers, cache ~/.texliveYY so repeated latexmk runs stay fast—or use the default Tectonic engine to minimise setup.
  • macOS – Use MacTeX or BasicTeX plus the tlmgr packages reported by texsmith --template <name> --template-info. Homebrew’s mactex cask works well when paired with uv.
  • Windows – TeXSmith runs via native Python or WSL. For PDF builds we recommend MiKTeX + PowerShell, or WSL2 with TeX Live and Docker Desktop (needed for Mermaid).
  • Docker workflows – Run texsmith --build inside a TeX Live container, mounting your project plus the template directory. Copy tlmgr prerequisites from --template-info so images compile without network access.

See the Getting Started guide for a step-by-step walkthrough, verification commands, and Python API examples.

Documentation

Browse the full documentation at yves-chevallier.github.io/texsmith for:

Template catalog

Inspect templates by name or path to understand their slots, metadata attributes, TeX Live requirements, and declared assets:

texsmith --template article --template-info
# or inspect a local path
texsmith --template ./templates/nature --template-info
texsmith templates  # view discovery order across built-ins/packages/local/home

Use this command before wiring slots or when you need to confirm which tlmgr packages to preinstall in CI.

Examples

The examples/ directory includes reproducible demos:

  • examples/paper – end-to-end render with bibliographies and latexmk (or Tectonic with --engine tectonic).
  • examples/diagrams – Mermaid and Draw.io conversions.
  • examples/markdown – exhaustive Markdown showcase with diagram/front-matter overrides.

Each example ships build instructions inside docs/examples/index.md.

Project layout

The source tree is organised around three top-level namespaces:

  • texsmith.core contains the conversion pipeline, document models, diagnostics, and template helpers.
  • texsmith.adapters hosts infrastructure integrations such as Markdown parsing, LaTeX rendering, Docker helpers, and transformer utilities.
  • texsmith.ui provides end-user interfaces, including the Typer-powered CLI.

Core architecture highlights

  • ConversionService encapsulates the orchestration that previously lived in texsmith.api.service helpers. Provide a ConversionRequest and receive a ConversionResponse with rendered bundles and diagnostics.
  • TemplateRenderer now owns slot aggregation and LaTeX assembly. TemplateSession focuses on session state, template options, and bibliography tracking.
  • DocumentSlots unify slot directives from front matter, CLI flags, and programmatic overrides. Every entry point now speaks the same data model.
  • DiagnosticEmitter replaces ad-hoc callback bags so warnings, errors, and structured events flow through a predictable interface (CLI uses CliEmitter; libraries can plug in their own).
  • Fragments use a BaseFragment + config dataclass model (fragment = YourFragment() export referenced by fragment.toml entrypoints). No legacy factories remain.

Programmatic conversions with ConversionService

from pathlib import Path

from texsmith import ConversionRequest, ConversionService

service = ConversionService()
request = ConversionRequest(
    documents=[Path("docs/index.html")],
    bibliography_files=[Path("references.bib")],
    template="article",
    render_dir=Path("build"),
)
prepared = service.prepare_documents(request)
response = service.execute(request, prepared=prepared)

print("Main TeX:", response.render_result.main_tex_path)
print("Diagnostics:", [event.name for event in response.diagnostics])

If you only need a quick conversion, the high-level helpers (texsmith.Document, texsmith.convert_documents, texsmith.TemplateSession) continue to work, but they now reuse the same ConversionService plumbing as the CLI.

Refer to UPGRADE.md for release notes and migration guidance from earlier builds.

Render pipeline

TeXSmith lowers every document into a typed intermediate representation (IR) and then emits a backend from that IR:

read(HTML) → IR (texsmith.ir) → write(IR) → LaTeX | Typst
  • Readers (texsmith.readers.html) turn BeautifulSoup nodes into backend-agnostic IR nodes. A reader lowering is a callable decorated with @reads(*tags, level, priority, name); it returns an IR node and never mutates the tree.
  • IR (texsmith.ir) is a typed, backend-neutral node tree. Semantic hints travel as Span/Div attributes rather than backend strings.
  • Writers emit a backend from the IR. texsmith.writers.latex.LaTeXWriter (default) and texsmith.writers.typst.TypstWriter register emitters with @writes(NodeType), dispatched by node class along the MRO. A node without an emitter raises a clear, localised error naming the node and backend.

Select the backend with --format {latex,typst}. See the Output backends guide and the Readers & Writers reference for the decorators and a runnable extension example.

Metadata

Release files for texsmith 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for texsmith 0.6.0
File Size Uploaded
texsmith-0.6.0.tar.gz 6.7 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for texsmith 0.6.0
File Interpreter ABI Platform
texsmith-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.3 MB

Release files / texsmith-0.6.0.tar.gz

Download URL texsmith-0.6.0.tar.gz
Size 6.7 MB
Tags Source
SHA-256 checksum
How to use checksums
612dcaf6251523abfd08a31a1728f848f7b0b1cd52d76cce20bfd37c4edbd2bb
BLAKE2b-256 checksum
How to use checksums
900b06737bf16cb7f5cdb04278c6696b0001cf3332a96dd3924d3e4ebc4bd08d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / texsmith-0.6.0-py3-none-any.whl

Download URL texsmith-0.6.0-py3-none-any.whl
Size 659.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
61808f16b23151be8790677667b4ecba138c7fce728e53104fb60c5e6bcfb8d9
BLAKE2b-256 checksum
How to use checksums
7d30917b701678ea94431de226354caed62c755148c419391a55614babc55c15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release history Release notifications | RSS feed

0.9.3

2 release files

0.9.2

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

This release

0.6.0 This release

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page