Skip to content
pineapplehunterPublic

About

Tectonic with texlive packages from Nix

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

Tectonix

Tectonix wraps the Tectonic LaTeX compiler and uses TeX Live packages from Nix instead of Tectonic's downloadable bundle. You get the TeX Live version from a pinned nixpkgs revision, and you can commit the package list so collaborators and CI can build with the same dependencies.

$ tectonix sample.tex # produces "sample.pdf"

How to use

Install Nix first. The first time you run tectonix sample.tex, Tectonix discovers the TeX Live packages your document needs, writes vendor.toml beside sample.tex, and compiles the PDF. Commit vendor.toml with your sources. Later runs reuse it without updating it, and flags such as --keep-logs are passed through to Tectonic.

To keep the lock elsewhere, pass --vendor-file PATH when you compile, build, or regenerate it:

$ tectonix --vendor-file locks/paper.toml paper/main.tex
$ tectonix --vendor-file locks/paper.toml build paper/main.tex
$ tectonix --vendor-file locks/paper.toml vendor paper/main.tex

PATH must point to a .toml file. Relative paths are resolved from the directory you run the command in, and the parent directory must already exist. If the lock is missing, a normal compile discovers dependencies and writes it to the specified path. This option is for standalone documents; workspace locks stay in Tectonic.toml.

Keep chapters, figures, and local styles under the main file's directory. Discovery and sandboxed builds copy that source tree into the Nix store, so use a dedicated project directory and keep secrets outside it.

With flakes

Open a shell with Tectonix on PATH, then compile your document:

$ nix shell github:pineapplehunter/tectonix
$ tectonix sample.tex

Or run it directly from your document directory:

$ nix shell github:pineapplehunter/tectonix -c tectonix sample.tex

The Nix package also provides nextonix for Tectonic workspaces. Run nextonix build in an existing workspace, or create one with nextonix new my-paper. The generated default workspace builds to build/default/default.pdf. Workspaces store their lock inside Tectonic.toml under doc.metadata.tectonix.vendor instead of creating vendor.toml.

Without flakes

From a checkout of this repository, install Tectonix into your Nix profile:

$ nix-env -if .

Then switch to your document directory and run tectonix sample.tex. No flakes, experimental Nix commands, or configured nixpkgs channel are required.

Install with uv

From a checkout of this repository:

$ uv tool install .

This installs the tectonix command; you still need nix-build on PATH. Use tectonix -X build in place of nextonix build with this installation.

Build a document with Nix

Use the locked, sandboxed build for CI. It requires an existing vendor lock and never updates it:

$ tectonix build sample.tex

To expose the PDF as a Nix derivation, use mkDocument. For example, save this as document.nix next to a tectonix/ checkout and a paper/ directory containing sample.tex and vendor.toml:

let
  tx = import ./tectonix/lib.nix;
in
tx.mkDocument {
  src = ./paper;
  mainFile = "sample.tex";
}

Run nix-build document.nix to get result/document.pdf. Pass a directory as src if your document needs chapters or figures; passing a single .tex file only includes that file.

In a flake, the same function is exported as inputs.tectonix.lib.mkDocument. Pass system explicitly for pure evaluation, or pass your project's pkgs to use its nixpkgs instead of the document's pin. Using a different pkgs can change the output even when the package list stays the same. To read a lock from another location, set vendorFile = ./locks/paper.toml;.

Regenerate the vendor lock

After adding a dependency, explicitly rerun discovery and commit the updated lock:

$ tectonix vendor sample.tex

For a workspace, run nextonix vendor (or tectonix -X vendor). If automatic lookup is ambiguous, you can give discovery a package name, for example tectonix vendor sample.tex tcolorbox. If discovery or verification fails, the existing lock is left intact.

Override Tectonic or Biber

By default, Tectonix uses Tectonic and Biber from the same nixpkgs pin as the document's TeX Live packages. Nixpkgs' standard Tectonic wrapper instead uses an older Biber to match Tectonic's downloadable bundle.

When using the Tectonix Nix package or overlay, pass a custom Tectonic package to override. For nixpkgs' Tectonic wrapper, the Biber argument is named biber-for-tectonic:

pkgs.tectonix.override {
  tectonic = pkgs.tectonic.override {
    biber-for-tectonic = custom-biber;
  };
}

The override applies to both tectonix and nextonix, without changing the TeX Live pin or packages in the document's lock. For a Nix document build, pass the same custom package as tectonic to mkDocument. If you use Biber, choose a version compatible with your document's biblatex version.

Run the tests

Run nix flake check to build the Tectonix package and five locked test documents: basic LaTeX, Japanese text, graphics and math, traditional BibTeX, and biblatex with the Biber backend. To run one document check, use e.g. nix build --no-link .#checks.x86_64-linux.bibtex (substitute your Nix system).

After changing a fixture's dependencies, regenerate its lock with tectonix vendor tests/<name>/main.tex.

How it works

  1. Tectonix starts a sandboxed build with a small TeX Live installation. When the compiler reports a missing file, Tectonix looks for its owner in the pinned TeX Live package catalogue and retries with that package.
  2. For a standalone document, it records which TeX Live packages supplied files the compiler actually read. Workspace builds don't report individual file reads, so their locks keep the small baseline plus any extra packages found during discovery.
  3. Tectonix rebuilds with the candidate lock and saves it only if the PDFs match byte for byte. On later builds, Nix assembles the locked packages into a local bundle that Tectonic reads in place of its usual bundle.

Discovery targets PDF builds with default compile options. Biber is supplied by the compiler wrapper, not listed in the vendor lock. Discovery does not cover dependencies for shell escape or named system fonts. Workspace discovery also requires PDF-only profiles with no extra_paths.

About

Tectonic with texlive packages from Nix

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages