2020-12-03 02:15:18 -03:00
# TeX Live {#sec-language-texlive}
2024-11-17 11:33:33 +01:00
There is a TeX Live packaging that lives entirely under attribute `texlive` .
2020-12-03 02:15:18 -03:00
2023-11-07 19:39:42 +00:00
## User's guide (experimental new interface) {#sec-language-texlive-user-guide-experimental}
Release 23.11 ships with a new interface that will eventually replace `texlive.combine` .
- For basic usage, use some of the prebuilt environments available at the top level, such as `texliveBasic` , `texliveSmall` . For the full list of prebuilt environments, inspect `texlive.schemes` .
- Packages cannot be used directly but must be assembled in an environment. To create or add packages to an environment, use
```nix
2025-04-11 09:36:54 +02:00
texliveSmall.withPackages (
ps: with ps; [
collection-langkorean
algorithms
cm-super
]
)
2023-11-07 19:39:42 +00:00
```
The function `withPackages` can be called multiple times to add more packages.
- **Note.** Within Nixpkgs, packages should only use prebuilt environments as inputs, such as `texliveSmall` or `texliveInfraOnly` , and should not depend directly on `texlive` . Further dependencies should be added by calling `withPackages` . This is to ensure that there is a consistent and simple way to override the inputs.
- `texlive.withPackages` uses the same logic as `buildEnv` . Only parts of a package are installed in an environment: its 'runtime' files (`tex` output), binaries (`out` output), and support files (`tlpkg` output). Moreover, man and info pages are assembled into separate `man` and `info` outputs. To add only the TeX files of a package, or its documentation (`texdoc` output), just specify the outputs:
```nix
2025-04-11 09:36:54 +02:00
texlive.withPackages (
ps: with ps; [
texdoc # recommended package to navigate the documentation
perlPackages.LaTeXML.tex # tex files of LaTeXML, omit binaries
cm-super
cm-super.texdoc # documentation of cm-super
]
)
2023-11-07 19:39:42 +00:00
```
- All packages distributed by TeX Live, which contains most of CTAN, are available and can be found under `texlive.pkgs` :
```ShellSession
$ nix repl
nix-repl> :l < nixpkgs >
nix-repl> texlive.pkgs.[TAB]
```
Note that the packages in `texlive.pkgs` are only provided for search purposes and must not be used directly.
- **Experimental and subject to change without notice:** to add the documentation for all packages in the environment, use
```nix
texliveSmall.__overrideTeXConfig { withDocs = true; }
```
This can be applied before or after calling `withPackages` .
The function currently support the parameters `withDocs` , `withSources` , and `requireTeXPackages` .
2020-12-03 02:15:18 -03:00
## User's guide {#sec-language-texlive-user-guide}
- For basic usage just pull `texlive.combined.scheme-basic` for an environment with basic LaTeX support.
2021-06-05 21:22:45 +02:00
2022-03-14 14:46:36 +01:00
- It typically won't work to use separately installed packages together. Instead, you can build a custom set of packages like this. Most CTAN packages should be available:
2020-12-03 02:15:18 -03:00
```nix
texlive.combine {
2025-04-11 09:36:54 +02:00
inherit (texlive)
scheme-small
collection-langkorean
algorithms
cm-super
;
2020-12-03 02:15:18 -03:00
}
```
- There are all the schemes, collections and a few thousand packages, as defined upstream (perhaps with tiny differences).
2021-06-05 21:22:45 +02:00
2020-12-03 02:15:18 -03:00
- By default you only get executables and files needed during runtime, and a little documentation for the core packages. To change that, you need to add `pkgFilter` function to `combine` .
```nix
texlive.combine {
# inherit (texlive) whatever-you-want;
2025-04-11 09:36:54 +02:00
pkgFilter =
pkg: pkg.tlType == "run" || pkg.tlType == "bin" || pkg.hasManpages || pkg.pname == "cm-super";
2020-12-03 02:15:18 -03:00
# elem tlType [ "run" "bin" "doc" "source" ]
# there are also other attributes: version, name
}
```
- You can list packages e.g. by `nix repl` .
```ShellSession
$ nix repl
nix-repl> :l < nixpkgs >
nix-repl> texlive.collection-[TAB]
```
- Note that the wrapper assumes that the result has a chance to be useful. For example, the core executables should be present, as well as some core data files. The supported way of ensuring this is by including some scheme, for example `scheme-basic` , into the combination.
2023-09-03 12:02:34 +01:00
- TeX Live packages are also available under `texlive.pkgs` as derivations with outputs `out` , `tex` , `texdoc` , `texsource` , `tlpkg` , `man` , `info` . They cannot be installed outside of `texlive.combine` but are available for other uses. To repackage a font, for instance, use
```nix
2025-04-19 22:09:31 +02:00
stdenvNoCC.mkDerivation (finalAttrs: {
2023-09-03 12:02:34 +01:00
src = texlive.pkgs.iwona;
2024-06-03 03:16:13 +03:00
dontUnpack = true;
2023-09-03 12:02:34 +01:00
2025-04-19 22:09:31 +02:00
inherit (finalAttrs.src) pname version;
2023-09-03 12:02:34 +01:00
installPhase = ''
runHook preInstall
2024-06-03 03:16:13 +03:00
install -Dm644 $src/fonts/opentype/nowacki/iwona/*.otf -t $out/share/fonts/opentype
2023-09-03 12:02:34 +01:00
runHook postInstall
'';
2025-04-19 22:09:31 +02:00
})
2023-09-03 12:02:34 +01:00
```
See `biber` , `iwona` for complete examples.
2020-12-03 02:15:18 -03:00
## Custom packages {#sec-language-texlive-custom-packages}
2023-11-20 00:56:40 +00:00
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` .
2020-12-03 02:15:18 -03:00
2023-11-20 00:56:40 +00:00
The functions `texlive.combine` and `texlive.withPackages` recognise the following outputs:
2023-03-11 20:57:23 +00:00
2023-11-20 00:56:40 +00:00
- `"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.
2020-12-03 02:15:18 -03:00
```nix
2025-04-11 09:36:54 +02:00
with import < nixpkgs > { };
2020-12-03 02:15:18 -03:00
let
2023-11-20 00:56:40 +00:00
foiltex = stdenvNoCC.mkDerivation {
2020-12-03 02:15:18 -03:00
pname = "latex-foiltex";
version = "2.1.4b";
2023-11-20 00:56:40 +00:00
2025-04-11 09:36:54 +02:00
outputs = [
"tex"
"texdoc"
];
2023-11-20 00:56:40 +00:00
passthru.tlDeps = with texlive; [ latex ];
2020-12-03 02:15:18 -03:00
srcs = [
(fetchurl {
url = "http://mirrors.ctan.org/macros/latex/contrib/foiltex/foiltex.dtx";
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 19:49:00 +00:00
hash = "sha256-/2I2xHXpZi0S988uFsGuPV6hhMw8e0U5m/P8myf42R0=";
2020-12-03 02:15:18 -03:00
})
(fetchurl {
url = "http://mirrors.ctan.org/macros/latex/contrib/foiltex/foiltex.ins";
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 19:49:00 +00:00
hash = "sha256-KTm3pkd+Cpu0nSE2WfsNEa56PeXBaNfx/sOO2Vv0kyc=";
2020-12-03 02:15:18 -03:00
})
];
unpackPhase = ''
runHook preUnpack
for _src in $srcs; do
cp "$_src" $(stripHash "$_src")
done
runHook postUnpack
'';
2023-11-20 00:56:40 +00:00
nativeBuildInputs = [
2025-04-11 09:36:54 +02:00
(texliveSmall.withPackages (
ps: with ps; [
cm-super
hypdoc
latexmk
]
))
2023-11-20 00:56:40 +00:00
# multiple-outputs.sh fails if $out is not defined
(writeShellScript "force-tex-output.sh" ''
out="''${tex-}"
'')
2025-04-19 21:37:21 +02:00
writableTmpDirAsHomeHook # Need a writable $HOME for latexmk
2023-11-20 00:56:40 +00:00
];
2020-12-03 02:15:18 -03:00
dontConfigure = true;
buildPhase = ''
runHook preBuild
# Generate the style files
latex foiltex.ins
2023-11-20 00:56:40 +00:00
# Generate the documentation
latexmk -pdf foiltex.dtx
2020-12-03 02:15:18 -03:00
runHook postBuild
'';
installPhase = ''
runHook preInstall
2023-11-20 00:56:40 +00:00
path="$tex/tex/latex/foiltex"
mkdir -p "$path"
cp *.{cls,def,clo,sty} "$path/"
path="$texdoc/doc/tex/latex/foiltex"
2020-12-03 02:15:18 -03:00
mkdir -p "$path"
2023-11-20 00:56:40 +00:00
cp *.pdf "$path/"
2020-12-03 02:15:18 -03:00
runHook postInstall
'';
Nix docs: remove `with lib;` from example code
Following [Best Practices](https://nix.dev/guides/best-practices#with-scopes),
`with` is a problematic language construction and should be avoided.
Usually it is employed like a "factorization": `[ X.A X.B X.C X.D ]` is written
`with X; [ A B C D ]`.
However, as shown in the link above, the syntatical rules of `with` are not so
intuitive, and this "distributive rule" is very selective, in the sense that
`with X; [ A B C D ]` is not equivalent to `[ X.A X.B X.C X.D ]`.
However, this factorization is still useful to "squeeze" some code, especially
in lists like `meta.maintainers`.
On the other hand, it becomes less justifiable in bigger scopes. This is
especially true in cases like `with lib;` in the top of expression and in sets
like `meta = with lib; { . . . }`.
That being said, this patch removes most of example code in the current
documentation.
The exceptions are, for now
- doc/functions/generators.section.md
- doc/languages-frameworks/coq.section.md
because, well, they are way more complicated, and I couldn't parse them
mentally - yet another reason why `with` should be avoided!
2024-03-06 08:51:54 -03:00
meta = {
2024-07-20 09:08:30 +02:00
description = "LaTeX2e class for overhead transparencies";
Nix docs: remove `with lib;` from example code
Following [Best Practices](https://nix.dev/guides/best-practices#with-scopes),
`with` is a problematic language construction and should be avoided.
Usually it is employed like a "factorization": `[ X.A X.B X.C X.D ]` is written
`with X; [ A B C D ]`.
However, as shown in the link above, the syntatical rules of `with` are not so
intuitive, and this "distributive rule" is very selective, in the sense that
`with X; [ A B C D ]` is not equivalent to `[ X.A X.B X.C X.D ]`.
However, this factorization is still useful to "squeeze" some code, especially
in lists like `meta.maintainers`.
On the other hand, it becomes less justifiable in bigger scopes. This is
especially true in cases like `with lib;` in the top of expression and in sets
like `meta = with lib; { . . . }`.
That being said, this patch removes most of example code in the current
documentation.
The exceptions are, for now
- doc/functions/generators.section.md
- doc/languages-frameworks/coq.section.md
because, well, they are way more complicated, and I couldn't parse them
mentally - yet another reason why `with` should be avoided!
2024-03-06 08:51:54 -03:00
license = lib.licenses.unfreeRedistributable;
maintainers = with lib.maintainers; [ veprbl ];
platforms = lib.platforms.all;
2020-12-03 02:15:18 -03:00
};
};
2023-11-20 00:56:40 +00:00
latex_with_foiltex = texliveSmall.withPackages (_: [ foiltex ]);
2020-12-03 02:15:18 -03:00
in
2025-04-11 09:36:54 +02:00
runCommand "test.pdf"
{
2020-12-03 02:15:18 -03:00
nativeBuildInputs = [ latex_with_foiltex ];
2025-04-11 09:36:54 +02:00
}
''
cat >test.tex < < EOF
\documentclass{foils}
\title{Presentation title}
\date{}
\begin{document}
\maketitle
\end{document}
EOF
pdflatex test.tex
cp test.pdf $out
''
2020-12-03 02:15:18 -03:00
```
2024-01-12 16:47:35 +01:00
## 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
2025-04-11 09:36:54 +02:00
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
''
2024-01-12 16:47:35 +01:00
```
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
```