Home Explore Blog CI



nixpkgs

4th chunk of `doc/languages-frameworks/texlive.section.md`
bbeb2be545586850a354c12e7548c3f5b8c8b4d7e545ad2e0000000100000c22
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" ''
        out="''${tex-}"
      '')
      writableTmpDirAsHomeHook # Need a writable $HOME for latexmk
    ];

    dontConfigure = true;

    buildPhase = ''
      runHook preBuild

      # Generate the style files
      latex foiltex.ins

      # Generate the documentation
      latexmk -pdf foiltex.dtx

      runHook postBuild
    '';

    installPhase = ''
      runHook preInstall

      path="$tex/tex/latex/foiltex"
      mkdir -p "$path"
      cp *.{cls,def,clo,sty} "$path/"

      path="$texdoc/doc/tex/latex/foiltex"
      mkdir -p "$path"
      cp *.pdf "$path/"

      runHook postInstall
    '';

    meta = {
      description = "LaTeX2e class for overhead transparencies";
      license = lib.licenses.unfreeRedistributable;
      maintainers = with lib.maintainers; [ veprbl ];
      platforms = lib.platforms.all;
    };
  };

  latex_with_foiltex = texliveSmall.withPackages (_: [ foiltex ]);
in
runCommand "test.pdf"
  {
    nativeBuildInputs = [ latex_with_foiltex ];
  }
  ''
    cat >test.tex <<EOF
    \documentclass{foils}

    \title{Presentation title}
    \date{}

    \begin{document}
    \maketitle
    \end{document}
    EOF
      pdflatex test.tex
      cp test.pdf $out
  ''
```

## LuaLaTeX font cache {#sec-language-texlive-lualatex-font-cache}

The font cache for LuaLaTeX is written to `$HOME`.
Therefore, it is necessary to set `$HOME` to a writable path, e.g. [before using LuaLaTeX in nix derivations](https://github.com/NixOS/nixpkgs/issues/180639):
```nix
runCommandNoCC "lualatex-hello-world"
  {
    buildInputs = [ texliveFull ];
  }
  ''
    mkdir $out
    echo '\documentclass{article} \begin{document} Hello world \end{document}' > main.tex
    env HOME=$(mktemp -d) lualatex  -interaction=nonstopmode -output-format=pdf -output-directory=$out ./main.tex
  ''
```

Additionally, [the cache of a user can diverge from the nix store](https://github.com/NixOS/nixpkgs/issues/278718).
To resolve font issues that might follow, the cache can be removed by the user:
```ShellSession
luaotfload-tool --cache=erase --flush-lookups --force
```

Title: Custom TeX Package Derivation: FoilTeX Example (Part 2) & LuaLaTeX Font Cache
Summary
This section completes the FoilTeX example derivation. It defines `nativeBuildInputs`, including a script and `writableTmpDirAsHomeHook` for LaTeXmk. The `buildPhase` generates style files and documentation. The `installPhase` copies files to the correct TDS structure. It sets `meta` attributes. A `latex_with_foiltex` variable creates a TeX Live environment with FoilTeX. A `runCommand` creates a test PDF. The second part covers the LuaLaTeX font cache, written to `$HOME`. It highlights setting `$HOME` to a writable path before using LuaLaTeX in Nix. It mentions cache divergence between user and Nix store, offering a command (`luaotfload-tool --cache=erase --flush-lookups --force`) to resolve font issues.