LATEX Weekend
A Fachschaft WIAI workshop. Presented by Alice, Christian, Clara, Evelyn, Fabian, Florian, Jochen, Katharina, Kilian, Paul, and Sandra.
A Fachschaft WIAI workshop. Presented by Alice, Christian, Clara, Evelyn, Fabian, Florian, Jochen, Katharina, Kilian, Paul, and Sandra.
Goal: You are going to build your own little
LaTeX manual based on our LaTeX
Script.
Outline:
The “LaTeX vs. Word” debate is very old. If you are interested in tracing it, we can recommend the following article as a starting point:
Moorhead, A.V. Is LaTeX use correlated with the number of equations in a manuscript? Scientometrics 126, 8259–8273 (2021).
(TL;DR: LaTeX users make more errors, they need more time except when it comes to formulas, but they are happier with their tool.)
Image source: xkcd
install-verification/main.tex in
TEXstudio.Windows: In order to enable file endings, click the
view tab in the file explorer, and select file name extensions.
This helps differentiating the different main files.
Text typesetting is particularly good when it is not conspicuous. Or to put it another way: Good typesetting makes for effortless reading. This website impressively demonstrates the role played by fonts and font sizes, line spacing and many other factors:
https://legibility.info/legible-readable
The best thing about it: LaTeX does most of this manual work for us.
General structure of a command:
\<command>[<optional_parameters>]{<obligatory_parameters>}
A few examples:
\newpage % inserts a new page
\textbf{bold text} % formats the text bold
\documentclass[a4paper,12pt,landscape]{article} % configures the document class
\frac{1}{4} % inserts a mathematical fractionAssuming a German keyboard layout, you get the backslash by pressing
AltGr + ß (Windows/Linux)
Alt + Shift + 7 (MacOS)
👁 Every LaTeX document is composed of
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\begin{document}
Hello world!
\end{document}
\documentclass[<parameter>]{<document_class>}
For example:
\documentclass[10pt,a5paper,landscape]{article}
\usepackage[utf8]{inputenc}
\usepackage[t1]{fontenc}
\usepackage[ngerman]{babel}
babel provides
language-specific information (e. g., hyphenation, special characters,
font changes, translated labels like ‘chapter,’ ‘table of contents’ or
‘figure’).ngerman is the German new
spelling.Continous text can be written directly ↲
in the source code. ↲
Simple line breaks ↲
are ignored, ↲
just as multiple space characters. ↲
↲
An empty line creates a new paragraph ↲
which has an indentation by default. ↲
Manual line breaks can be forced ↲
using two backslashes, but this use ↲
is strongly discouraged \\ ↲
within continuous text.
After a percent sign, the rest of the line is ignored by the compiler. It is called a comment and does not appear in the resulting document.
% profile start
Name: Donald Knuth \\
Date of birth: \\ % TODO: insert
Place of birth: Milwaukee, Wisconsin
% profile end
Shortcuts: Ctrl + T and Ctrl + U
Some characters do things in LaTeX:
# $ % ^ & _ { } ~ \
50% is one half.
Solution: prefix with ‘\’:
50\% is one half.
Does not work for ‘\\’, use \textbackslash
instead. Also: Consider using a thin space
between numbers and units (50\,\%).
Texts are structured by beeing subdivided in sections and chapters. Always available:
\section{Level 1}
\subsection{Level 2}
\subsubsection{Level 3}
\paragraph{Level 4}
\subparagraph{Level 5}
Additionally, for some document classes:
\chapter{Chapter}
\part{Part}
\title{The World of Truffles}
\author{Fooboar Rüssel \and Fachschaft WIAI}
\date{\today}
\begin{document}
\maketitle
\end{document}
\maketitle typesets the title page within the document
environment.\and.\date{}.\documentclass{article}
\usepackage{babel}
\title{The World of Truffles}
\author{Fooboar Rüssel
\and Fachschaft WIAI}
\date{\today}
\begin{document}
\maketitle
\section{Truffle hunt}
\subsection{Hunt with a pig}
\subsection{Hunt without a pig}
Why would you do that?
\section{Truffle recipes}
My favorite recipe
\end{document}
\tableofcontents
\listoffigures
\listoftables
*) are hidden from the
register: e. g. \section*{}.\documentclass{article}
\usepackage{babel}
\begin{document}
\tableofcontents
\section{Truffle hunt}
The first section.
\subsection{Hunt with a pig}
A subsection.
\subsection{Hunt without a pig}
Another subsection.
\subsubsection[But why?]{Why would
you do that?}
Sub-subsection.
\section{Truffle recipes}
My favorite recipe
\end{document}
Close all open tabs from previous tasks.
document-structure.tex. It is located in
the directory exercises/basic-document-structure.\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\\’. Use real paragraphs instead.\section,
\subsubsection, etc.).article.scr document classes usually adhere to
European layout norms.Following document classes are available:
scrartcl, article for
short documentsscrreprt, report for
longer documentsscrbook, book for
booksbeamer for presentationsA document can use multiple languages at once:
\usepackage[ngerman, swedish, ukrainian, greek, english]{babel}
To switch languages:
\selectlanguage{<language a>}
\selectlanguage{<language b>}
Embedded Text in another language:
\selectlanguage{<language a>}
\foreignlanguage{<language b>}{Text of language B in a text of language A}
\today
\selectlanguage{ngerman}
\today
\selectlanguage{swedish}
\today
\selectlanguage{ukrainian}
\today
\selectlanguage{greek}
\today
\selectlanguage{english}
\today
With an asterisk, there is no numbering and no entry in the table of contents:
\section*{No entry in table of contents}
You can also provide an alternative title for the table of contents:
\section[Entry in table of contents]
{Actual chapter heading}
The fancyhdr package helps us with that.
% activate in general
\pagestyle{fancy}
% apply to the first page as well
\thispagestyle{fancy}
% reset values
\fancyhead{} % and/or \fancyfoot{}
\fancyhead[L]{Left header}
\fancyfoot[C]{Center footer}
\fancyfoot[R]{\thepage}
A comprehensive tutorial can be found on Overleaf.
twocolumn).Create a bigger LaTeX project and …
\input{path/to/file}
\documentclass{article}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\title{A Title}
\begin{document}
\maketitle
\tableofcontents
\input{section1.tex}
\input{section2.tex}
\end{document}
\begin{document} or
\end{document}
\section{This is section 1}
A paragraph about the content
of section 1.
% …
\section{This is section 2}
A paragraph about the content
of section 2.
% …
Close all open tabs from previous tasks.
You will find a file named main.tex in the folder
exercises/project-structure.
section1.tex and section2.tex.\input command.main-exercises.tex (in the root folder of the project
archive). How do we include the different sections here?The pdfpages package allows for embedding entire PDF
documents.
\includepdf[pages={<from>-<to>}]{<file>}
Further options make multiple pages appear in tiles and change the orientation to landscape, among other things. See the package documentation for a complete list.
It may be helpful to specify custom macros for often-used code.
\newcommand{\<name>}[<parameter_count>][<default>]{<content>}
In the script, we used these macros for margins and acronyms (see
commands.tex for more examples):
\newcommand{\widefiguremargin}{-.22\textwidth}
\newcommand{\acro}[1]{\textsc{\lowercase{#1}}}
It is also possible to customize existing commands. \(\LaTeX\) even allows you to use programming patterns like variables, conditionals, and loops. To learn more, have a look at this WikiBook chapter.
\input{}, but later also for other media
types\input{}, you can specify the path relative to the
main file
In LaTeX, you have to use UNIX-style paths. They are
separated by a forward slash: path/to/file. We will use
those from here on.
main-exercises.tex → praeamble.tex
./praeamble.tex
A single dot ‘.’ represents the current
folder (in this case: latex-script). It is optional, you
could also write praeamble.tex here.
main-exercises.tex →
basic-document-structure.tex (in a subfolder)
./content/basic-document-structure.tex
basic-functionality.tex → graphics.raw.tex
(basic-functionality.tex is imported into
main-exercises.tex)
./exercises/graphics/graphics.raw.tex
Paths are always relative to the root document that imports other files as fragments.
main-exercises.tex in the project root.\,) and non-breaking spaces
(~), where appropriate.Thin spaces are used in abbreviations
and before units, e.\,g., 10\,s.
Normal-width non-breaking spaces can help
keep honorary titles and names on one
line: Dr.~Fooboar.
\frenchspacing) to avoid giant
gaps after full stops.| Name | Use | Code | |
|---|---|---|---|
| - | Hyphen | compound-forming hyphen |
-
|
| – | En dash (Halbgeviertstrich) | a dash – or a range: 12 – 2 p.m. |
--
|
| — | Em dash (Geviertstrich) | a dash — mostly in American English |
---
|
The csquotes package provides, amongst others, the
command \enquote.
\enquote{A \enquote{nested}
quote.}
When included with autostyle=true, foreign-language
quotes use the according quotation marks:
\foreignquote{ngerman}{Ein deutsches
Zitat.}
From now on, compile the file main-exercises.tex to see
your changes appear in the exercise script (in this task, see exercise
5).
exercises/special-characters.tex
within the abbreviations (“e. g.”, “i. a.”) by thin
spaces.--), optionally surrounded by thin
spaces.\enquote command.In English, LaTeX uses the old-fashioned English spacing, i. e., double sentence spacing.
If you want to be more modern, you can use
\frenchspacing above your first paragraph.
\nonfrenchspacing goes back to default.
If you actually use English spacing, LaTeX will still try and put normal word spacing after abbreviations. However, you should check the results and intervene where needed by
.\␣
\@.␣
Most of the time, LaTeX hyphenates words correctly if the correct language is configured. Sometimes, manual intervention is required.
| Exclusive hyphenation |
\-
|
| Additional hyphenation |
"-
|
| Hyphen (suppressing other hyphenation) |
-
|
| Hyphen (allowing other hyphenation) |
"=
|
| Possible separation without hyphen |
""
|
| Non-breaking hyphen |
"~
|
Some of the codes only work when you use the babel package.
| Language | Command | Result |
|---|---|---|
| English (B. E.) |
`…'
|
‘ … ’ |
| 2nd Level |
``…''
|
“ … ” |
| English (A. E.) |
``…''
|
“ … ” |
| 2nd Level |
`…'
|
‘ … ’ |
| German |
\glqq … \grqq
|
„ … “ |
| 2nd Level |
\glq … \grq
|
‚ … ’ |
| German altern. |
\frqq … \flqq
|
» … « |
| 2nd Level |
\frq … \flq
|
› … ‹ |
Other rules my apply for other languages (mostly: the same characters, but combined differently).
Letters with diacritics can either by typed directly on the keyboard or via escape codes:
\`{o}
|
ò |
\c{c}
|
ç |
\d{u}
|
ụ |
\'{o}
|
ó |
\k{a}
|
ą |
\r{a}
|
å |
\^{o}
|
ô |
\l{}
|
ł |
\u{o}
|
ŏ |
\"{o}
|
ö |
\={o}
|
ō |
\v{s}
|
š |
\H{o}
|
ő |
\b{o}
|
o |
\t{oo}
|
o͡o |
\~{o}
|
õ |
\.{o}
|
ȯ |
\o
|
ø |
Special characters can also be typed directly or created via escape codes and commands:
| ¿ |
?`
|
¡ |
!`
|
| ^ |
\textasciicircum
|
~ |
\textasciitilde
|
| * |
\textasteriskcentered
|
\ |
\textbackslash
|
| | |
\textbar
|
∙ |
\textbullet
|
| ⓒ |
\textcopyright
|
† |
\textdagger
|
| ‡ |
\textdaggerdbl
|
… |
\textellipsis
|
| < |
\textless
|
> |
\textgreater
|
| ‰ |
\textperthousand
|
§ |
\textsection
|
… and pretty much anything else.
\emph{}
| Name | Befehl |
|---|---|
| Bold (bold face) |
\textbf{important}
|
| Italics (italics) |
\textit{important}
|
| Small caps |
\textsc{important}
|
| non-proportional (teletype) |
\texttt{important}
|
| underlined |
\underline{important}
|
Some well-meaning advice
You want the entire document to look consistent?
Trust LaTeX’s defaults (font sizes of title, paragraphs, footnotes, etc.)!
This conversely means: Avoid fiddling around with font sizes manually.
The hyperref package provides an \url{}
command that reproduces URLs
\url{https://www.latex-project.org/}
With \href{}{}, the URL is hidden in an interactive
link.
\href{https://latex-project.org/news/}{blog}
exercises/text-markup/markup.tex
using \emph{…}.csquotes package.{\<fontsize> some text}
Font sizes relative to normalsize:
{\tiny If}
{\footnotesize you}
{\small can}
{\normalsize read}
{\large this,}
{\Large you}
{\LARGE don’t}
{\huge need}
{\Huge glasses.}
By default, LaTeX sets text in full justification, but it is possible to activate ragged alignment.
\raggedright … \raggedleft …
\centering …
Alternatively, we can use dedicated environments:
\begin{flushleft} Text \end{flushleft}
\begin{flushright} Text \end{flushright}
\begin{center} Text \end{center}
Proper ragged alignment is even more difficult than good justification, so better avoid it.
\parindent)\parskip)
instead (!)\setlength{\parindent}{0pt}
\setlength{\parskip}{1em
plus .5em % permitted stretch
minus .5em % permitted compression
}
\noindent allows us to disable first-line indentation
for a given paragraph\begin{itemize}
\item lasagna noodles
\item crushed tomatoes, % …
\item oregano, basil, % …
\item mozzarella cheese
\item flour
\item milk
\end{itemize}
We mark each bullet point with \item. This pattern is
the same for all kinds of enumerations.
\begin{enumerate}
\item cook onions over medium % …
\item add crushed tomatoes, carrots % …
\item add herbs and spices % …
% \item …
\end{enumerate}
\begin{description}
\item [Béchamel sauce] Béchamel % …
\item [Lasagne] Lasagne (singular % …
\end{description}
\begin{itemize}
% …
\item vegetables \begin{itemize}
\item crushed tomatoes
\item carrots
\end{itemize}
\item herbs \begin{enumerate}
\item oregano
\item basil
\end{enumerate}
% …
\end{itemize}
lists.tex into an unordered
list consisting of the elements Ingredients and
Instructions. You can find the file in the directory
exercises/lists. Use the itemize command.The package paralist offers enumerations with less line
spacing.
\section{Ingredients}
\begin{compactitem}
% \item …
\end{compactitem}
\section{Preparation}
\begin{compactenum}
% \item …
\end{compactenum}
\section{Glossary}
\begin{compactdesc}
% \item …
\end{compactdesc}
Another feature provided by paralist enables us to
integrate enumerations into paragraphs.
The following herbs are % …
\begin{inparaitem}
\item lovage
\item parsley
\item chives
\end{inparaitem}
Of course, there is an accompanying list type called
inparaenum for ordered lists.
The list style type can be set using the optional parameter
label. To accomplish this, we need to include the package
enumitem first (but after all other list-related
packages).
% Roman numerals
\begin{enumerate}[label=\roman*]
% …
% Arabic numerals
\begin{enumerate}[label=\arabic*]
% …
% Alphabetical
\begin{enumerate}[label=\alph*]
% …
\setcounter).$2 \sqrt{\frac{\pi^2}{3} \cdot c_2}$
Mathematical formulas are only accepted in the so-called math
mode. In-line formulas must therefor be guarded by two dollar
signs. We can also use the equation block environment:
\begin{equation}
2 \sqrt{\frac{\pi^2}{3} \cdot c_2}
\end{equation}
Packages: amsmath, amsthm,
amssymb, mathtools
| source code | result |
|---|---|
\sum_{i=1}^{n}x^2
|
\(\sum_{i=1}^{n} x^2\) |
12 \leq 4 x^2 + 13
|
\(12 \leq 4 x^2 + 13\) |
{n \choose k}
|
\({n \choose k}\) |
The align environment permits us to align equations at
certain positions like the ‘ = ’ character.
\begin{align}
13 \cdot (4a - 3)^2 &= 13 … \\
&= 208a^2 - 312a + 117
\end{align}
&’).\\’.align and equation will not be numbered
if we add an asterisk after their names (e. g.
\begin{align*} and \end{align*}).Code up the following formulas in the file
exercises/maths/math-formulas.tex.
| Meaning | Result |
|---|---|
| Gravitational acceleration | \(9.81\,\frac{m}{s^2}\) |
| One formula to solve quadratic equations | \(x_{1,2} = - \frac{p}{2} \pm \sqrt{\left(\frac{p}{2}\right)^2 - q}\) |
| The other one | \(x_{1,2} = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}\) |
| Catalan numbers | \(C_n = \frac{1}{n+1} {2n \choose n} = \frac{(2n)!}{(n+1)!n!}\) |
| Meaning | Result |
|---|---|
| Definition of factorial | \(n! = \prod_{i=1}^{n} i\) |
| Set of all odd natural numbers | \(\{ x \mid x \in \mathbb{N}, \text{odd}(x) \}\) |
| Elimination \(\neg\exists x\) | \(\neg\exists x . p(x) \Leftrightarrow \forall x . \neg p(x)\) |
Find further examples on the Chair of Algorithms and Complexity Theory’s LaTeX exercise page.
| source code | result |
|---|---|
(x), [x], \lbrace x \rbrace,
\lvert x \rvert
|
\((x), [x], \lbrace x\rbrace, \lvert x\rvert\) |
\exists, \forall, \in,
\notin, \infty
|
\(\exists,\forall,\in,\notin,\infty\) |
\alpha, \beta, \Gamma,
\Delta, \varepsilon, \pi
|
\(\alpha, \beta, \Gamma, \Delta, \varepsilon, \pi\) |
\rightarrow, \leftarrow,
\Rightarrow, \Leftarrow,
\Leftrightarrow
|
\(\rightarrow, \leftarrow, \Rightarrow, \Leftarrow, \Leftrightarrow\) |
(A \cup B) \cap C
|
\((A \cup B) \cap C\) |
(A \lor B) \land C
|
\((A \lor B) \land C\) |
(A \cdot B) \times C
|
\((A \cdot B) \times C\) |
| source code | result |
|---|---|
\left( \frac{1}{2} \right)
|
\(\left( \frac{1}{2} \right)\) |
\left[ \frac{1}{2} \right]
|
\(\left[ \frac{1}{2} \right]\) |
\left\lbrace \frac{1}{2} \right\rbrace
|
\(\left\lbrace \frac{1}{2} \right\rbrace\) |
$4 \cdot \left( \frac{1}{2} % …
\(4 \cdot \left(\frac{1}{2} +\frac{3}{ 12 \cdot \left( 2 + \frac{1}{86 \cdot \left(\frac{1}{2} + 24 \right)} \right)} \right)\)
The bounds of an integral can be enforced to appear above and below
the integral symbol using the \limits command. This is the
standard behaviour for sums, products and limits.
\sum_{i=1}^{n^2}(x+2)
\prod_{j=1}^{100}(3 \cdot x)
\lim_{x \rightarrow \infty}(14x^3 - 12)
\int\limits_{-12}^{4}(14x^3 - 12)
Don’t use \limits inline.
In certain situations, it is more adequate to use textual predicates or long function names within the set builder notation.
This is where \text{} comes into play.
\(\left\lbrace x \mid frequency(x) \geq 20\right\rbrace\)
\(\left\lbrace x \mid \text{frequency}(x) \geq 20\right\rbrace\)
$\left\lbrace x \mid \text{frequency} …
To display graphics, we need the graphicx package.
\begin{figure}
\includegraphics{<file path>}
\caption[<short caption (table of
figures)>]{<full caption>}
\end{figure}
Specifying the size:
\includegraphics[width=0.5\textwidth,
height=5cm]{<file path>}
\begin{figure}[<position code>]
LaTeX places graphics automatically. With position codes, we can express our preferences (they can be combined as well).
| code | position |
|---|---|
| h | here, if you don’t mind |
| t | top of the page |
| b | bottom of the page |
| p | on its own page |
| H |
Here, for God’s sake! ( float package required)
|
\begin{figure}[<position>]
\begin{center}
\includegraphics{<path-to-file>}
\end{center}
\end{figure}
Alternatively:
\begin{figure}[<position>]
\centering
\includegraphics{<path-to-file>}
\end{figure}
exercises/graphics you can find an
image file named latex-logo.png.exercises/graphics/graphics.tex and place it
exactly where you include it.\textwidth).For typographically pleasing tables, we use the booktabs
package.
\usepackage{booktabs}
\begin{table}[<position>]
\caption{<caption>}
\begin{tabular}{<column definition>}
% table content
\end{tabular}
\end{table}
Positioning works just like with graphics.
\begin{tabular}{lrcl}
% table content
\end{tabular}
| letter | meaning |
|---|---|
| l | left-justified column |
| c | centred column |
| r | right-justified column |
Vertical separator lines and double horizontal lines are frowned upon by typographers and should be avoided.
\begin{tabular}{lll}
\toprule
Column 1 & Column 2 & Column 3 \\
\midrule
Content a & Content b & Content c \\
Content e & Content f & Content g \\
Content i & Content j & Content k \\
\bottomrule
\end{tabular}
&’.\\’.\toprule, \midrule and
\bottomrule structure the table.\begin{table}[h]
\caption{Well-known programming languages}
\begin{tabular}{lrcl}
\toprule
Language & Author & Year & File extension \\
\midrule
C++ & Bjarne Stroustrup & 1985 & .cpp \\
Java & James Gosling & 1998 & .java \\
Python & Guido van Rossum & 1991 & .py \\
\bottomrule
\end{tabular}
\end{table}
@{} to the left and right of a column definition removes
the padding of the corresponding column.
\begin{tabular}{@{}lrcl@{}} limits the row separators to
the width of the table content
The Tables Generator is a wonderful tool to quickly create tables of different formats.
exercises/tables/tables.tex stores
information on a few modules of the WIAI faculty.Tables that exceed one page are simply cut off by
tabular. A solution is offered by the
longtable package:
\usepackage{longtable}
\begin{longtable}{<column definition>}
\caption{<caption>}
\label{<label>}
% table content
\end{longtable}
longtable
\begin{longtable}{<column definition>}
\caption{<caption>}
\label{<label>}
% table content
\end{longtable}
longtable environment merges the
tabular and table environments.booktabs package is used, its features
are also provided in longtable.If you need a table to be wider than a page, you can display it in landscape orientation:
\usepackage{rotating}
\begin{sidewaystable}[<position>]
\begin{tabular}{<column def.>}
% table content
\end{tabular}
\end{sidewaystable}
\usepackage[table]{xcolor}
\begin{tabular}{lll}
\toprule
A & \cellcolor{yellow}yellow & cell \\
A & \cellcolor{yellow!25}lighter yellow & cell \\
\rowcolor[HTML]{FFDE21}
A & yellow & row \\
\bottomrule
\end{tabular}
\cellcolor to color individual cells.\rowcolor to color entire rows.yellow!25), or hex ([HTML]{...}).\begin{tabular}{lll}
\toprule
Animal & Food & Size \\
\midrule
horse & hay & large \\
frog & flies & small \\
fooboar & \multicolumn{2}{c}{unknown} \\
\bottomrule
\end{tabular}
\multicolumn{2}{c}{...} combines two columns into
one.\usepackage{makecell}
\begin{tabular}{ll}
\toprule
Name & Description \\
\midrule
Cat & \makecell[l]{small \\ likes to sleep} \\
Dog & \makecell[l]{loyal \\ needs walks} \\
\bottomrule
\end{tabular}
\makecell centers its contents.\makecell[l]{content} to left-align the
content.The p{4cm} column automatically wraps text within
4cm.
\begin{tabular}{lp{4cm}}
\toprule
Item & Description \\
\midrule
Chair & Four legs, one surface \\
Table & Like a chair but different \\
\bottomrule
\end{tabular}
\begin{table}[h]
\begin{tabular}{llr}
\toprule
Structure & \multicolumn{2}{l}{Access time complexity} \\ \cmidrule(r){2-3} & Average & Worst \\
\midrule
Stack & $\mathcal{O}(n)$ & $\mathcal{O}(n)$ \\
Binary tree & $\mathcal{O}(log(n))$ & $\mathcal{O}(n)$ \\
AVL tree & $\mathcal{O}(log(n))$ & $\mathcal{O}(log(n))$ \\
\bottomrule
\end{tabular}
\end{table}
booktabs package provides commands for high-quality
tables:Footnotes are automatically numbered consecutively, independent of sections.
The wild boar (\textit{Sus scrofa}), also
known as the wild swine, common wild pig,
or simply wild pig, is a suid native to
much of Eurasia and North Africa, and has
been introduced to the Americas and Oceania.
\footnote{\url{https://en.wikipedia.org/
wiki/Wild_boar}}
Manually (just don’t!)
As you can see in Figure 23, …
Using the \ref command:
\begin{figure}[H]
\includegraphics % …
\caption{Our mascot Fooboar}
\label{fig:fooboar}
\end{figure}
As you can see in Figure
\ref{fig:fooboar}, …
Both cross-reference commands work with sections, figures, tables, listings, and equations, as long as you use correct labels.
Labels have to be unambiguous. For clarity, certain prefixes are common, and some packages use them to derive information.
fig: Figures
|
tbl: Tables
|
sec: Sections
|
subsec: Subsections
|
ch: Chapters
|
itm: Enumeration items
|
eq: Equations
|
lst: Source code listings
|
Using the cleveref package (with one ‘r’!):
\begin{figure}[H]
\includegraphics % …
\caption{Our mascot Fooboar}
\label{fig:fooboar}
\end{figure}
Fooboar is a young and highly committed
boar (see \Cref{fig:fooboar}).
The \cref command automatically inserts suitable
prefixes.
Terms inserted by \cref use the language specified
with the document class (or babel):
\documentclass[english]{article}
Apart from sections, referenced elements need captions
(\caption{…}), and the captions have to be placed
before the label.
For sectioning commands, the label is inserted directly after the section command.
\section{Notes}\label{sec:notes}
exercises/footnotes/footnotes.tex appear as a
footnote.exercises/references/references.tex, replace
In the figure and The following source code listing by
references to the figure and to the source code
listing.\Cref for the references.\lstinputlisting command. Use the
Internet, if necessary.The footmisc package provides additional options for the
presentation of footnotes that can be activated by adding parameters to
the \usepackage command.
% Reset the counter on each page:
\usepackage[perpage]{footmisc}
% Display footnotes in-line:
\usepackage[para]{footmisc}
% Use symbols instead of numbers:
\usepackage[symbol]{footmisc}
hyperref
before cleveref.\cref can take multiple references at once, separated
by commas.\section{An introduction}
\label{sec:section1}
% …
Reference be made to
\Cref{sec:section1,sec:section2,
sec:section3,sec:section5}.
The listings package provides a dedicated
environment:
\section*{Haskell Magic}
Squares of all even % …
\begin{lstlisting}[language=Haskell]
[x^2 | x <- [1..200], even x]
\end{lstlisting}
Conveniently, listings offers an import command:
\section*{Simple Java Application}
\lstinputlisting[language=Java]{Test.java}
public class Test {
public static void main(/*…*/) {
System.out.println(/*…*/);
}
}
listings does not provide any themes by default, but can
be configured extensively.
\begin{lstlisting}[
language=Java,
basicstyle=\footnotesize\ttfamily,
breaklines=true,
keywordstyle=\color{ForestGreen},
commentstyle=\color{DarkGray},
literate={ö}{{\"o}}1
]
% …
\end{lstlisting}
Have a look at the \lstset command for creating your own
themes.
xcolor
package for colorslistings
Source.java in the file
source-code-listings.tex (mind the relative file
path!).literate option.basicstyle to a proper mono-spaced font
(\ttfamily \small).If you have questions, try to consult the documentation of the
listings package.
.bib
file) for storing referencesPreparing TeXstudio:
BibLaTeX
Biber
.bib file?
@article{turing1990, % the type of the document and an identifier for the \cite command
title={The chemical basis of morphogenesis}, % information
author={Turing, Alan Mathison}, % about
journal={Bulletin of mathematical biology}, % the
volume={52}, % literature
pages={153--197}, % work
date={1990}, % follows
publisher={Springer} % …
}
[1] Note: Even though we are working with BibLaTeX, our bibliography file adheres to the conventions of BibTeX, which is an alternative program. The name has been established for all kinds of things related to LaTeX citations. This is similar to the way we refer to online search by the name of one popular search engine.
Some well-meaning advice
You want the references to look professional?
Trust BibLaTeX’s default citation styles!
This conversely means: Avoid fiddling around with styles manually.
authoryear,
numeric, alphabetic)apa, ieee,
chicago-authordate)\usepackage[style=numeric, citestyle=ieee,
backend=biber]{biblatex}
Two things are infinite: the universe and the assortment of citation styles.Unknown
\usepackage[style=numeric, citestyle=ieee,
sorting=nty, backend=biber]{biblatex}
| Code | Description |
|---|---|
| nty | Name, Title, Year |
| nyt | Name, Year, Title |
| nyvt | Name, Year, Volume, Title |
| ydtn | Year (descending), Title, Name |
BibLaTeX adds some citation commands to LaTeX. In addition, we need
the natbib package.
| Code | Description |
|---|---|
\parencite{turing1990}
|
[Turing, 1990] |
\textcite{turing1990}
|
Turing (1990) |
\textcite[p. 159]{turing1990}
|
Turing (1990, p. 159) |
Citing with additional
text:\cite[<prefix>][<suffix>]{<source>}
\usepackage[style=authoryear,
maxnames=3,
minnames=1,
nohashothers=true,
dashed=false,
url=false,
backend=biber]{biblatex}
An exemplary reference in the citation style above:
… in parentheses \parencite{thatcher2002}
or simply as \textcite{thatcher2002} …
literature.bib in the
exercises/literature folder.alphabetic bibliography style.exercises/literature/literature.tex.Not: If the compilation fails, it may be helpful to
remove all temporary files
(….aux/bbl/blg/loc/out/pdf/soc/toc) and to compile
again.
biblatex)💡 Further information
There are plenty of resources about the setup available online.
Better BibTeX for Zotero
Better BibLaTex as
format, and set keep updated to true.bib-file\usepackage{makeidx}
\makeindex
\begin{document}
\maketitle
\section{What is LaTeX\index{LaTeX}?}
LaTeX\index{LaTeX} is a typesetting
system\index{Typesetting system}.
\newpage \section{TeX\index{TeX} vs.
LaTeX\index{LaTeX}} It is based on
TeX\index{TeX}, an invention by
Donald Knuth\index{Knuth, Donald}.
As TeX\index{TeX} is way more complex
syntactically than LaTeX\index{LaTeX},
LaTeX\index{LaTeX} is much more
popular.
\printindex
For slides, there is the beamer document class, as well
as numerous templates and
themes.
\documentclass{beamer}
\usetheme{Frankfurt}
\usecolortheme{seahorse}
\usepackage[utf8]{inputenc}
\begin{document}
\begin{frame}
\frametitle{Lemon sorbet}
\framesubtitle{Incarnation of good?}
\begin{definition}
A lemon sorbet is a
semi-frozen \textbf{dessert}
on \textit{lemon} base.
\end{definition}
\end{frame}
\end{document}
TikZ (“TikZ ist kein Zeichenprogramm” — “TikZ is no
drawing software”) is a powerful package for drawing vector
graphics.
% …
\tikzstyle{every node}=[draw=black,thick,anchor=west]
\tikzstyle{selected}=[draw=red,fill=red!30]
\tikzstyle{dir}=[fill=gray!50]
\tikzstyle{relativeTo}=[fill=blue!70]
\begin{tikzpicture}[%
grow via
three points={one child at (0.5,-0.7) and
two children at
(0.5,-0.7) and (0.5,-1.4)},
edge from
parent path={(\tikzparentnode.south)
|- (\tikzchildnode.west)}]
\node {/ or C:}
child { node {home}
child { node {knut}
child { node {pictures}}
child { node {docs}
child { node [dir] {latex}
child { node [relativeTo] {main.tex}
child { node [selected] {part1.tex}
}
}
}
};
\end{tikzpicture}
The qtree package can render constituent-based parse
trees:
\Tree [.S [.NP LaTeX ]
[.VP [.V is ] [.NP fun ] ] ]
Logical tableaux can be renderd using the prftree
package.
\begin{displaymath}
\prftree[l,r]{}{[comp$\_{ns}$]}
{
\prftree[l,r]{}{[comp$\_{ns}$]}
{
\prftree[l,r]{}{[ass$\_{ns}$]}
{
-
}
{
(\texttt{m:=a}, \sigma\_{\bot,\bot})
\rightarrow \sigma\_{48,\bot}
}
}
{
\prftree[l,r]{}{[ass$\_{ns}$]}
{
-
}
{
(\texttt{n:=b}, \sigma\_{48,\bot})
\rightarrow \sigma\_{48,18}
}
}
{
(\texttt{m:=a; n:=b}, \sigma\_{\bot,\bot})
\rightarrow \sigma\_{48,18}
}
}
{
\prftree[l,r]{}{}
{
\dots
}
{
\textbf{[1]}\ (\texttt{LOOP}, \sigma\_{48,18})
\rightarrow \sigma\_{6,6}
}
}
{
(\texttt{m:=a; n:=b; LOOP}, \sigma\_{\bot,\bot})
\rightarrow \sigma\_{6,6}
}
\end{displaymath}
The LaTeX Wikibook offers numerous interesting articles and is available in English and German (among others).

The “Comprehensive TeX Archive Network” is the central source for LaTeX packages and their documentation.

Overleaf is a collaborative online LaTeX editor.
It also offers a multiple tutorials and templates for different occasions (CV, theses, …): »Templates«.

📍WE5/02.104
☎️0951 863 1219
📧fachschaft-wiai.stuve@uni-bamberg.de

