6.2 KiB
Introductory Course to \LaTeX
What even is \LaTeX?
- 1978: Donald Knuth gets fed up by typographical errors in his documents and creates \TeX
- 1984: Leslie Lamport gets fed up with having to write bonkers \TeX\ -commands and piles on a bunch of macros
- 2025: We're here, still stuck with this ancient crap
But actually, it is a pretty good document preparation system.
(a modern alternative is Typst)
What even is a document preparation system?
It is a system that prepares your documents!
Crucial elements:
- What are the contents of the document?
- Where should all the words and sentences go?
- What do we do about equations, figures and tables?
- We need references and appendices and other things, right?!?
First Principle of \LaTeX
Separate content and presentation.
- General classes/types of content
- Styling applies to the entire document
- Just write, and deal with making it pretty later
- The publisher will mangle your document anyways
Second Principle of \LaTeX
Let the system handle book keeping.
- Don't manually update captions and figure numbers
- Don't manually update captions and table numbers
- Don't manually write/update/sort your list of references
Now, how do we use it?
Types of content
- Frontmatter
- Sections, subsections, paragraphs
- Math: both inline and standalone
- Figures and tables
- References (bibiolgraphy)
- Appendices
Document structure
- Preamble
- Frontmatter - title, table of content, list of figures/tables
- (The acutal) Document
- Sections/Chapters
- Text
- Math
- Figures
- Tables
- Sections/Chapters
- Bibliography
- Appendices
Document setup
- Type of document:
\documentclass
- Preamble with
\input
- Document body with
\begin{document}
- This is an environment
- Frontmatter with
\maketitle
- Sections with
\input
- Bibliography with
\bibliography
- Appendices with
\appendix
Part 0: Preamble
Here you might stick:
\usepackage
-directives- Custom commands
- For instance those defined with
\newcommand
- For instance those defined with
- Setup for packages used in the document
- Directives for the presentation of the types of content in the document
\vspace{2em}
Tip: Make you preamble self-contained and portable
Basic structure of a \LaTeX\ command
\commandname[optionalarguments]{requriedarguments}
Examples:
\usepackage[paper=a4paper]{geometry}
\emph{Hello!}
Part 1: Content
Since content and presentation is mostly separate:
- Content type must be specified in the "raw content"
- Presentation will be defined "elsewhere"
Environments and displays define what you write means
Types of environments:
- Document, math, figure, table, list, quote, bold, italics
Usually specified in the text with:
\begin{contenttype}
... what you write goes here
\end{contenttype}
Normal text: headings, paragraphs, lists
- Headings
\section
,\subsection
,\subsubsection
- Paragraphs
- Just add some linebreaks!
- An empty line signifies the boundary between paragraphs
- Lists
itemize
: bullet pointsenumerate
: numbered list- Can be nested
\vspace{2em}
Tip: For better version control, stick to one sentence, one line
MATH
equation
: a single line of mathgather
: multiple lines of mathalign
: multiple lines that can be lined up\(...\)
: inline math\[...\]
: basically likeequation
We're talking inline F = ma
versus full display:
E = mc^2.
Figures and tables
\begin{figure}
: figure environment\includegraphics
: the graphics to be shown\caption
: text under/over the figure, with number\label
: name to remember the figure by in the raw latex
\begin{table}
: table environment\begin{tabular}
: environment for tabulated data\caption
: text over/under table, with number\label
: allows you to refer to the table in the document
Referencing
\usepackage{biblatex}
- Reference list styling
- Many other options
- Needs a file containing available sources
- Put
\addbibresource
in the preamble
- Put
\printbibliography
- Options are available for this one as well
Appendices
\usepackage{appendix}
\appendix
: changes context of the document to "appendices"- Each
\section
now defines an appendix, not a "chapter" - Should probably have been an environment, but alas
- Each
Part 2: Presentation
I used to fight all the time with my typesetter about where the images should be placed. Now I use \LaTeX\ and have accepted that I'll never win.
. . .
The \TeX \ typesetting engine is really powerful and will probably make better choices than you.
Linebreaks and pagebreaks
- Empty line: separates paragraphs
- Depending on settings, this may not produce empty lines in the compiled document
\\
: forces linebreak- Used in tables, matrices and multiline math
- Can force air between paragraphs, but be careful
\newpage
: forces the rest of the page to be empty\mbox
: forces words to "stay together", no hyphenation~
: non-breaking space
vspace and hspace
\vspace
: vertical spacing\hspace
: horizontal spacing- Valid lengths are:
cm, mm, em, ex, pt, mu, sp
- ... and some more
- Lengths may be negative
Defualt/documentwide lengths and widths
\parskip
: space when skipping to next paragraph\parindent
: indent space on the first line of a paragraph\baselinestretch
: how tall is a line?\setstretch
and\itemsep
: line height in itemize/enumerate environments
MATH - but displaystyle this time
\textstyle
: inline math, when using\(...\)
\displaystyle
: math in it's own box- With
equation
,gather
,align
and\[...\]
- With
\scriptstyle
: when showing in sub/superscript\scriptscriptstyle
: when sub/superscript is nested!
Figures and tables
- Width, height and angle:
[width=\textwidth, height=100mm, angle=45]
[!htbp]
- Here, top, bottom and "special page"
- Floats
- They float around and cannot be broken up
Part 3: Custom commands
\newcommand
: make a new one!\renewcommand
: change an existing one
Some examples: