Home Explore Blog CI



nixpkgs

3rd chunk of `doc/languages-frameworks/texlive.section.md`
e508dbc3994e31d05d8394ad6fc1aa3174151fe351794f43000000010000084a
You may find that you need to use an external TeX package. A derivation for such package has to provide the contents of the "texmf" directory in its `"tex"` output, according to the [TeX Directory Structure](https://tug.ctan.org/tds/tds.html). Dependencies on other TeX packages can be listed in the attribute `tlDeps`.

The functions `texlive.combine` and `texlive.withPackages` recognise the following outputs:

- `"out"`: contents are linked in the TeX Live environment, and binaries in the `$out/bin` folder are wrapped;
- `"tex"`: linked in `$TEXMFDIST`; files should follow the TDS (for instance `$tex/tex/latex/foiltex/foiltex.cls`);
- `"texdoc"`, `"texsource"`: ignored by default, treated as `"tex"`;
- `"tlpkg"`: linked in `$TEXMFROOT/tlpkg`;
- `"man"`, `"info"`, ...: the other outputs are combined into separate outputs.

When using `pkgFilter`, `texlive.combine` will assign `tlType` respectively `"bin"`, `"run"`, `"doc"`, `"source"`, `"tlpkg"` to the above outputs.

Here is a (very verbose) example. See also the packages `auctex`, `eukleides`, `mftrace` for more examples.

```nix
with import <nixpkgs> { };

let
  foiltex = stdenvNoCC.mkDerivation {
    pname = "latex-foiltex";
    version = "2.1.4b";

    outputs = [
      "tex"
      "texdoc"
    ];
    passthru.tlDeps = with texlive; [ latex ];

    srcs = [
      (fetchurl {
        url = "http://mirrors.ctan.org/macros/latex/contrib/foiltex/foiltex.dtx";
        hash = "sha256-/2I2xHXpZi0S988uFsGuPV6hhMw8e0U5m/P8myf42R0=";
      })
      (fetchurl {
        url = "http://mirrors.ctan.org/macros/latex/contrib/foiltex/foiltex.ins";
        hash = "sha256-KTm3pkd+Cpu0nSE2WfsNEa56PeXBaNfx/sOO2Vv0kyc=";
      })
    ];

    unpackPhase = ''
      runHook preUnpack

      for _src in $srcs; do
        cp "$_src" $(stripHash "$_src")
      done

      runHook postUnpack
    '';

    nativeBuildInputs = [
      (texliveSmall.withPackages (
        ps: with ps; [
          cm-super
          hypdoc
          latexmk
        ]
      ))
      # multiple-outputs.sh fails if $out is not defined
      (writeShellScript "force-tex-output.sh" ''

Title: Custom TeX Package Derivation: FoilTeX Example (Part 1)
Summary
This section provides detailed instructions on creating a custom TeX package derivation using Nixpkgs, specifically focusing on the 'foiltex' package. It emphasizes the importance of adhering to the TeX Directory Structure (TDS) within the `tex` output. It outlines how `texlive.combine` and `texlive.withPackages` handle different outputs like `out`, `tex`, `texdoc`, `texsource`, `tlpkg`, `man`, and `info`, and how `tlType` is assigned when using `pkgFilter`. The foiltex derivation is initiated, defining metadata such as `pname`, `version`, and the `tex` and `texdoc` outputs. It specifies `tlDeps` for dependencies and utilizes `fetchurl` to retrieve the source files (foiltex.dtx and foiltex.ins) along with their corresponding SHA256 hashes. The `unpackPhase` copies these source files, and the `nativeBuildInputs` declares build dependencies like cm-super, hypdoc, and latexmk using `texliveSmall.withPackages`. Finally, a shell script is introduced...