Skip to main content

mpl-tectonic

mpl-tectonic makes Matplotlib's text.usetex pipeline use Tectonic instead of a traditional latex executable. It is a small, opt-in compatibility layer for Matplotlib 3.11.

Installation

Install the Python package together with its tightly constrained Matplotlib dependency:

python -m pip install mpl-tectonic

The tectonic executable is also required on PATH. It is an external runtime dependency, not a Python package. This repository's Pixi environment installs the validated Tectonic 0.15 release.

Usage

Importing mpl_tectonic does not change Matplotlib. Call enable() once before rendering any text with usetex:

import matplotlib.pyplot as plt
import mpl_tectonic

mpl_tectonic.enable()

with plt.rc_context({"text.usetex": True}):
    fig, ax = plt.subplots()
    ax.set_xlabel(r"energy $E / \Delta$")
    ax.set_title(r"$E_n = \hbar\omega(n + \frac{1}{2})$")
    fig.savefig("figure.pdf")  # PNG and SVG work too.

enable() is idempotent. It validates Matplotlib and Tectonic before changing anything, then installs the integration process-wide. The intentionally small public runtime API contains only mpl_tectonic.enable(); there is no disable, status, or context-manager API.

How it works

Matplotlib 3.11 can read XeTeX's XDV format, but its usetex manager invokes latex and expects a .dvi cache file. mpl-tectonic asks Tectonic for XDV, places it at the cache path Matplotlib expects, and adapts the remaining private integration points:

  • pdfLaTeX-only UTF-8 declarations are removed from Matplotlib's generated TeX;
  • native fonts and classic TeX resources are materialized from Tectonic's bundle, keeping resource resolution consistent with the compiler;
  • XDV native OpenType fonts use Matplotlib's TrueType PDF embedding path and safe PDF resource names;
  • Matplotlib's opaque one-byte native-glyph failure is replaced with an actionable error.

SVG text is emitted as vector glyph paths. Native PDF output contains embedded, subsetted fonts rather than converting an SVG or raster image.

Compatibility and limitations

  • Only Matplotlib >=3.11,<3.12 is supported. The narrow range is deliberate: the package patches six private Matplotlib integration points.
  • Activation is process-global and permanent. Call enable() during single-threaded application setup, before concurrent rendering begins.
  • PNG, path-based SVG, and native PDF are supported.
  • Every label must be valid TeX once text.usetex is enabled. For example, literal e^2/h must be written as $e^2/h$; the package intentionally does not rewrite project text.
  • The ordinary research-figure PDF regime—ASCII prose plus TeX math commands—is supported. Literal or TeX-accented non-ASCII prose may select an XDV native-font glyph ID above 255, which Matplotlib 3.11's PDF renderer cannot encode. In that case mpl-tectonic raises an explicit error advising SVG output or supported TeX math commands. SVG remains the path-based fallback for such labels.
  • Tectonic may need network access on its first run to obtain its default bundle, depending on how Tectonic was installed and cached.

Development

The locked Pixi workflow builds both distributions, tests the installed development package, inspects wheel and sdist contents, and installs and runs the full output checks from each artifact:

pixi run test

The same manifest also builds a noarch conda package with explicit Python, Matplotlib, and Tectonic runtime dependencies:

pixi run build-conda

The test task includes the local pre-commit suite: Ruff linting, a Ruff format check, and codespell. To apply formatting or install the Git hook explicitly, use:

pixi run format
pixi run install-hooks

GitHub Actions runs the same workflow. Version tags matching v* trigger a separate Trusted Publishing workflow: it builds once, tests those exact wheel and sdist files, transfers them as one immutable Actions artifact, and publishes without an API-token secret. The pypi environment must be configured for this repository in PyPI before a release can succeed.

License

BSD-3-Clause. See LICENSE.

Metadata

Release files for mpl-tectonic 0.1.1

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

Source distribution (sdist)

Source distribution for mpl-tectonic 0.1.1
File Size Uploaded
mpl_tectonic-0.1.1.tar.gz 35.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mpl-tectonic 0.1.1
File Interpreter ABI Platform
mpl_tectonic-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 43.3 kB

Release files / mpl_tectonic-0.1.1.tar.gz

Download URL mpl_tectonic-0.1.1.tar.gz
Size 35.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ecb794b4787c935b0407e1733d6df36d7fc363207ce5f8fea272c969d6d8203f
BLAKE2b-256 checksum
How to use checksums
6247a909103b4b2e98e70032511223bdfb1553ce7996304cded716e5e3ad73e3
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 Oct 9, 2026.

Transparency log

Release files / mpl_tectonic-0.1.1-py3-none-any.whl

Download URL mpl_tectonic-0.1.1-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
66a5984ef1bf97996a972a9b6955c79f0ff7beb5906b6558483d7cbd7f3c939d
BLAKE2b-256 checksum
How to use checksums
3ae454886117f13da9d9fe40c49a74c5d5fcaf613d61987ddd7927a777289600
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 Oct 9, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.1.0

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