Tex: Difference between revisions

imported>7c6f434c
Add an example of overriding a package version
DHCP (talk | contribs)
m fix indentation
 
(3 intermediate revisions by 3 users not shown)
Line 9: Line 9:
TeX-documents are not What-you-see-is-what-you-get, but written in plain text, containing tags, commands and functions that instruct the TeX-engine how to lay out the text (or figures or anything else) on the page.
TeX-documents are not What-you-see-is-what-you-get, but written in plain text, containing tags, commands and functions that instruct the TeX-engine how to lay out the text (or figures or anything else) on the page.


A minimal TeX-document can be created on the commandline using this shell-snippet:
<syntaxhighlight lang=bash>
 
$ cat > minimal.tex <<EOF
<pre>
cat > minimal.tex <<'EOF'
\documentclass{article}
\documentclass{article}
\begin{document}
\begin{document}
Line 18: Line 16:
\end{document}
\end{document}
EOF
EOF
</pre>
</syntaxhighlight>


The Nixpkgs-repository contains several TeX-compilers that have different advantages and disadvantages, support various output formats, encodings and have varying degrees of extensibility.
The Nixpkgs-repository contains several TeX-compilers that have different advantages and disadvantages, support various output formats, encodings and have varying degrees of extensibility.
Line 26: Line 24:
A good starting point is to install the TeX-Live basic setup:
A good starting point is to install the TeX-Live basic setup:


<code>nix-env -iA nixpkgs.texlive.combined.scheme-basic</code>
<syntaxhighlight lang=console>
$ nix-env -iA nixpkgs.texlive.combined.scheme-basic
</syntaxhighlight>


After installation, the command <code>pdflatex</code> should be available. Save the minimal example above in a file called minimal.tex and compile it with <code>pdflatex minimal.tex</code>
After installation, the command <code>pdflatex</code> should be available. Save the minimal example above in a file called minimal.tex and compile it with <code>pdflatex minimal.tex</code>
Line 32: Line 32:
The (pretty verbose) output will look similar to:
The (pretty verbose) output will look similar to:


<pre>
<syntaxhighlight lang=console>
$ pdflatex minimal.tex
$ pdflatex minimal.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2019/NixOS.org)
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2019/NixOS.org)
Line 47: Line 47:
Output written on minimal.pdf (1 page, 12502 bytes).
Output written on minimal.pdf (1 page, 12502 bytes).
Transcript written on minimal.log.
Transcript written on minimal.log.
</pre>
</syntaxhighlight>


Well done, you created your first PDF document on Nixos using TeX.
Well done, you created your first PDF document on Nixos using TeX.
Line 57: Line 57:
Let's fetch an a little more complex example:
Let's fetch an a little more complex example:


<code>curl -O https://raw.githubusercontent.com/latex3/latex2e/master/base/sample2e.tex</code>
<syntaxhighlight lang=console>
$ curl -O https://raw.githubusercontent.com/latex3/latex2e/master/base/sample2e.tex
</syntaxhighlight>


and process it
and process it
 
<syntaxhighlight lang=console>
<code>pdflatex sample2e</code>
$ pdflatex sample2e
</syntaxhighlight>


You can then use any PDF viewer to display it, e.g. <code>evince</code> in GNOME, <code>okular</code> in KDE, <code>xpdf</code> or <code>zathura</code> lightweight X11-viewer.
You can then use any PDF viewer to display it, e.g. <code>evince</code> in GNOME, <code>okular</code> in KDE, <code>xpdf</code> or <code>zathura</code> lightweight X11-viewer.
Line 90: Line 93:
Example code:
Example code:


<syntaxhighlight lang=nix>
pkgs.texlive.combine {
  scheme-medium = pkgs.texlive.scheme-medium // {
    pkgs = pkgs.lib.filter
      (x: (x.pname != "apxproof"))
      pkgs.texlive.scheme-medium.pkgs;
  };


    pkgs.texlive.combine {
  apxproof = { pkgs = [(pkgs.runCommand "apxproof" {
      scheme-medium = pkgs.texlive.scheme-medium // {
    src = pkgs.fetchurl {
        pkgs = pkgs.lib.filter
      url = "https://raw.githubusercontent.com/PierreSenellart/apxproof/1ac14c47b8351b693ca05eec73dca1332a517ac9/apxproof.sty";
          (x: (x.pname != "apxproof"))
      sha256 = "sha256-XSgtXsOwhMu2Wo4hVp8ZfaPWgjEEg3EBn5/BhD3xkMA=";
          pkgs.texlive.scheme-medium.pkgs;
    };
      };
    passthru = {
   
      pname = "apxproof";
      apxproof = { pkgs = [(pkgs.runCommand "apxproof" {
      version = "1.2.3";
        src = pkgs.fetchurl {
      tlType = "run";
          url = "https://raw.githubusercontent.com/PierreSenellart/apxproof/1ac14c47b8351b693ca05eec73dca1332a517ac9/apxproof.sty";
    };
          sha256 = "sha256-XSgtXsOwhMu2Wo4hVp8ZfaPWgjEEg3EBn5/BhD3xkMA=";
  }
        };
  "
        passthru = {
    mkdir -p $out/tex/latex/apxproof/
          pname = "apxproof";
    cp $src $out/tex/latex/apxproof/apxproof.sty
          version = "1.2.3";
  ")]; };
          tlType = "run";
}
        };
</syntaxhighlight>
      }
      "
        mkdir -p $out/tex/latex/apxproof/
        cp $src $out/tex/latex/apxproof/apxproof.sty
      ")]; };
    }




Line 122: Line 126:
As noted on [[TexLive]] there are several schemas available. If you know exactly which packages you are going to need you can follow the recipe on the [[TexLive]] page. Installing the Full-schema is always an option to be sure that you have everything you need, like so:
As noted on [[TexLive]] there are several schemas available. If you know exactly which packages you are going to need you can follow the recipe on the [[TexLive]] page. Installing the Full-schema is always an option to be sure that you have everything you need, like so:


<code>nix-env -iA nixpkgs.texlive.combined.scheme-full</code>
<syntaxhighlight lang=console>
$ nix-env -iA nixpkgs.texlive.combined.scheme-full
</syntaxhighlight>
 
If you are looking for a smaller package, you need to go the [https://raw.githubusercontent.com/NixOS/nixpkgs/refs/heads/master/pkgs/tools/typesetting/tex/texlive/tlpdb.nix Nixpkg's package specification] and search for the scheme-name. For each scheme the list of packages is listed there. Since the inclusion of packages is organized hierarchically, this will require some digging. (TODO: Is there a nix-command to find out?)


If you are looking for a smaller package, you need to go the [https://raw.githubusercontent.com/NixOS/nixpkgs/master/pkgs/tools/typesetting/tex/texlive/pkgs.nix Nixpkg's package specification] and search for the scheme-name. For each scheme the list of packages is listed there. Since the inclusion of packages is organized hierarchically, this will require some digging. (TODO: Is there a nix-command to find out?)
[[Category:Languages]]