Commit bcb4d692 authored by Alexander Povel's avatar Alexander Povel
Browse files

Move font hints from README into cookbook

Most of this content was duplication anyway
parent a99df094
Pipeline #121183 failed with stages
in 7 minutes
# A LaTeX Cookbook
# LaTeX Cookbook
......@@ -10,116 +10,5 @@
This repo contains a [LaTeX]( [document](cookbook.tex), usable as a cookbook (different "recipes" to achieve various things in LaTeX) and also as a template.
The resulting PDF covers LaTeX-specific topics and instructions on compiling the LaTeX source using Docker.
The resulting PDF covers LaTeX-specific topics and instructions on compiling the LaTeX source.
It is available for [**download**](
This very README is also made available for [download as a PDF](, converted from Markdown using [pandoc]( with the [*Eisvogel*]( template.
## Appendix
### Hints on Fonts
We use beautiful, capable fonts based on
[TeX Gyre](
for high-quality typesetting.
Particularly, [*TeX Gyre Pagella*](
as an open and free *Palatino* (by [Hermann Zapf](
It comes with [an accompanying math font](,
*TeX Gyre Pagella Math*.
This is *extremely* important, since only with two matching (or even basically identical
fonts like in our case) fonts will a document like this one here look good.
If math and text fonts don't mix well, it will look terrible.
If the math font is not highly capable and provides all the glyphs we need,
it will also look terrible.
There aren't very many high-quality free fonts with a math companion available,
see [this compilation](
A similar compilation of 'nice' fonts is [found here](,
however that is specifically for `pdflatex`, not `lualatex`.
Of all of the available ones, *Pagella* was chosen.
This can be changed with relative ease in the package options for the responsible package,
If the new font does not come with at least the same amount of features,
parts of the document might break!
There is also a list of
[symbols defined by unicode-math](
for reference.
`unicode-math` builds on top of and loads, then extends, `fontspec`.
`fontspec` is a package for `lualatex` and `xelatex` designed to allow usage of outside, system
fonts (as opposed to fonts that ship with latex distributions/packages).
These can be system-installed fonts, but **we bring our own fonts**, and they reside in this directory.
This is to ensure everyone can compile this repository/document,
as long as they have this subdirectory intact.
It is also OS-agnostic
(with system-installed fonts, calling them by their name can get really out of hand;
with plain filenames, we know exactly what to call them).
Some fonts ship with regular LaTeX distributions and are available *without* being explicitly installed by the user.
TeX Gyre fonts are an example.
These need to neither be included here nor installed, they are ship with the LaTeX installation (TeXLive).
The distinct advantage of `unicode-math` over its parent `fontspec` is the additional
feature of a **math font** (`\setmathfont`).
Note that `unicode-math` **requires** `lua(la)tex` or `xe(la)tex`.
You cannot compile this document with `pdf(la)tex`.
This also means that the packages `inputenc` and `fontenc` are *not needed*.
In fact, they are, as far as I know, incompatible and may break the document.
They used to be employed to allow advanced encoding for both the plain-text source as
well as the output PDF.
This allowed usage of Umlauts *etc.*, but that's a relic of a distant past.
In fact, if we wanted to, we could input Unicode characters *directly into the source code*,
*e.g.* `\(α = 2\)` over `\(\alpha = 2\)`
(we don't do this because we use an entirely different system in the form of [`glossaries-extra`](glossaries)).
Now, it remains to choose between `lualatex` and `xelatex`
(`luatex` and `xetex` exist too, but output to `DVI`, which we don't care for nowadays;
`lualatex` and `xelatex` output to `PDF`).
The choice falls to `lualatex` and is quite easy:
- we make use of the `contour` packages to print characters (of any color) with a thick
contour aka background around them (in any color as well).
Of course, the most obvious use is black text with a white contour.
Text set like that will be legible on various colored or otherwise obstructed
(for example by plot grids) page backgrounds.
To this purpose, there is the command `\ctrw{<text>}`, which is used *a lot*.
The `contour` capabilities don't care for math mode, font weight, size, shape...
it all just works.
Finally, the kicker here is that **it does not work in `xelatex`**.
I tried [this](
and [this](
and [this](
and lastly [this](
and eventually failed horribly.
- further, `pdflatex`, with its roots in probably the 80s,
still to this day has strict and low memory limits.
For more advanced computations, it will
[complain and claim to be out of memory](
(the good old `TeX capacity exceeded, sorry`),
when in reality the host computer has Gigabytes and Gigabytes of RAM to spare.
This lead to the package/library `tikz-externalize`,
which puts Ti*k*z-pictures into their own compile jobs.
That way, each job is much smaller and can succeed within memory limits.
Another way to solve the limitation is to increase all the various memory limits manually,
to arbitrarily high values.
That this seems laborious, hacky and, well, arbitrary, is quickly apparent.
Now, even if we used `tikz-externalize`, it truncates the features we can make use of.
Since it exports the Ti*k*z environments to outside PDFs and then inputs those,
**labels/references/links cannot really be supported**.
I noticed this when I wanted equation references as a legend
(if that is a good idea is another question ...).
So `tikz-externalize` and its many caveats
(despite it being a brilliant solution to a problem we shouldn't even be having anymore nowadays)
is off the table.
`lualatex` simply solves all these concerns: it allocates memory as required.
I don't know to what degree it does this (if it can fill up modern machine memory),
but I can compile our entire document with countless Ti*k*z environments and demanding
plots (with high `sample=` values) with no memory issues.
As far as I know, `xelatex` doesn't do this, so forget about it.
These two reasons are easily enough to choose `lualatex` over `xelatex`.
I don't have more reasons anyway, since otherwise, the programs are quite identical.
......@@ -10,8 +10,10 @@ likely using \hologo{pdfLaTeX} as your engine.
This is the go\-/to default for generating \abb{portable_document_format} output.
Its most popular modern alternatives are \hologo{XeLaTeX} and \hologo{LuaLaTeX}.
These two offer various new, shiny features, chief among which is Unicode
support through the package \ctanpackage{unicode-math}, which builds onto
\ctanpackage{fontspec} and extends it by capabilities for math fonts.
support through the \ctanpackage{unicode-math} package, which builds onto
\ctanpackage{fontspec} and extends it with math fonts capabilities.
Note that these packages \emph{require} \hologo{XeLaTeX} or \hologo{LuaLaTeX} use:
\hologo{pdfLaTeX} is \emph{old} and will no longer work.
More on that in \cref{ch:fonts_text}.
\hologo{LuaLaTeX} is preferred over \hologo{XeLaTeX} for the following reasons:
......@@ -20,12 +22,18 @@ More on that in \cref{ch:fonts_text}.
\contour{black}{\textcolor{white}{this}}, works.
For an application of that, see \cref{fig:bitmap_tikz} on
Getting \ctanpackage{contour} to work on \hologo{XeLaTeX} is somewhat impossible.
Getting \ctanpackage{contour} to work on \hologo{XeLaTeX} is somewhat impossible,
see also
\href{}{here} and
\item \hologo{LuaLaTeX} allocates as much memory as it happens to need.
The ancient limitations of \TeX{} are easily reached by packages like
\ctanpackage{tikz} and \ctanpackage{pgfplots}.
Circumventing that either feels hacky, or actually is hacky.
\texttt{tikzexternalize} is a great module, but has a long list of caveats.
\texttt{tikzexternalize} is a great module, but has some caveats, like
breakage of clickable references.
It solves a problem that should no longer exist in the first place.
\item The fantastic \ctanpackage{microtype} package has a number of unavailable
functionalities when using \hologo{XeLaTeX}.
......@@ -44,8 +52,8 @@ hit compile, wait, done%
Using high-quality fonts is one goal.
This includes the fantastic
\href{}{\TeX Gyre fonts},
of which the \textit{\href{}{Palatino}}
(by Hermann Zapf) clone \textit{\href{}{Pagella}}
of which the \emph{\href{}{Palatino}}
(by Hermann Zapf) clone \emph{\href{}{Pagella}}
was chosen for this document.
It comes with an accompanying
\href{}{math font}
......@@ -56,7 +64,20 @@ of the same name%
that is bogus and can be ignored.
Using both fonts together is made possible by the \ctanpackage{unicode-math} package.
There are not very many high\-/quality free fonts with a math companion available,
see also \href{}{this compilation}.
A similar compilation of \enquote{nice} fonts is
\href{}{found here},
however that is specifically for \hologo{pdfLaTeX}, not \hologo{LuaLaTeX}.
The font choice can be changed with relative ease in the options for the
\ctanpackage{unicode-math} package.
If a new font does not provide at least the same array of features,
parts of the document might break!
For reference, there is a list of
\href{}{symbols defined by \ctanpackage{unicode-math}}.
Using both normal and maths fonts in conjunction is made possible through the
\ctanpackage{unicode-math} package.
As such, an exact match of the text and math fonts is achieved.
This is important but often overlooked.
However, such a match is often plain unavailable in the typesetting tool at hand.
......@@ -119,7 +140,7 @@ Notice the balanced line endings and low number of hyphenation;
easy on the eyes and very readable.
\paragraph{Old approach}
The overwhelming majority of \LaTeX{} documents rely on the two lines
The overwhelming majority of \LaTeX{} documents relies on the two lines
......@@ -129,7 +150,7 @@ Since this is what most people still do, the two packages are still required.
However, these two packages should at least not be used for \emph{new} work anymore!
Using \hologo{LuaLaTeX}, they are not required anymore:
\item input encoding is automatically UTF-8 (as it should be in 2020),
\item input encoding is automatically UTF-8 (as it should be in \verb|$CURRENTYEAR|),
\item font encoding is also not required, since fully capable fonts are used,
which come with all the glyphs required.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment