Recall from the previous lesson that you write text in the document
environment.
The characters
a-z A-Z 0-9 + = * / ( ) [ ]
and the punctuation marks
, ; . ? ! : ` ' -
and the space, tab and enter can be used directly in LaTeX code for writing text.
This is a handbook about TeX, a new typesetting system intended for the creation of beautiful books and especially for books that contain a lot of mathematics.
\documentclass[a4paper]{article}
\begin{document}
This is a handbook about TeX, a new typesetting system intended for the
creation of beautiful books and especially for books that contain a lot
of mathematics.
\end{document}
Multiple spaces, tabs and line breaks are treated as a single space in LaTeX.
This looks like a normal sentence.
This looks like
a normal sentence .
However, a blank line creates a new paragraph. We will discuss this later.
The following characters are reserved characters:
$ % ^ & _ { } ~ \
This means they have a special meaning in LaTeX. We already saw how to
use {
, }
and \
. If you want to use reserved characters in your
text you can use commands:
\# \$ \% \^{} \& \_ \{ \} \~{} \textbackslash{}
When LaTeX encounters a %
at a line it will ignore the rest of this
line and all whitespace at the beginning of the next line. Hence, %
can be used to write comments in your code. For example
\newcommand{\CC}{\mathbf{C}} % This command defines the field C.
Comments are also useful to temporarily remove a piece of text from the output.
There are two ways to enter letters with accents like é, ñ and å or special characters: using commands and (sometimes) using your keyboard.
The first way to enter special characters is by using LaTeX commands. A list of some of these commands is displayed below. (A more extensive list can be found on wikibooks)
command | output | description |
---|---|---|
\'o |
ó | accent aigu |
\^o |
ô | circumflex |
\"o |
ö | umlaut, diaeresis |
\~o |
õ | tilde |
\.o |
ȯ | dot |
Note that we left {
}
out of these commands (we type \'e
instead
of \'{e}
) since we don’t need these brackets for commands consisting
of one non-letter.
On some but not all LaTeX editors you can use special characters by typing them on your keyboard as normal. Not all keyboards of course can type all accented characters, so it is very useful to know the commands for them.
LaTeX distinguishes three different types of dashes in text: the
hyphen -, the en dash - and the em dash —. These can be
inserted using -
, --
and ---
. Use an en dash to indicate a
range, for example ‘rows 1–10’. Use the em dash to denote a break in a
sentence: ‘He was running, Watson—running desperately’. In Dutch it is
common to surround the en dash by spaces: ‘Jacqueline vertrok – zonder
nog een woord te zeggen’.
An ellipsis is a sequence of three dots indicating that some text is
left out. For the right spacing one can use \ldots
.
Quotes are typeset with a backtick `
and an apostrophe '
.
‘quote’, “quote”, “A ‘quote’ inside a quote”
`quote', ``quote'', ``A `quote' inside a quote''
Typeset the following names twice: with and without using unicode. Hint: Erdős is Hungarian.
Kurt Gödel, Endre Szemerédi, Muhammed al-Khowârizmi, Paul Erdős
Typeset the sentence
“A mathematician is a device for turning coffee into theorems.” — Alfréd Rényi (1921–1970)
Paragraphs can be made in LaTeX by leaving a line blank. For example
Erdős’ high productivity can be seen from the fact that he published around 1500 scientific articles, most of them together with others. He worked together with about 500 collegues. thought of mathematical research as a social activity and changed the way of doing mathematics permanently.
He was engaged with number theory, combinatorics, set theory, analysis and stochastics, but made contributions to almost every subarea of mathematics.
In 1984 he won the most lucrative award in mathematics, the Wolf Prize, and used all but 720 of the USD 50,000 prize money to establish a scholarship in his parents’ memory in Israel.
\documentclass[a4paper]{article}
\begin{document}
Erd\H{o}s' high productivity can be seen from the fact that he
published around 1500 scientific articles, most of them together with
others. He worked together with about 500 collegues. Erd\H{o}s thought
of mathematical research as a social activity and changed the way of
doing mathematics permanently.
He was engaged with number theory, combinatorics, set theory, analysis
and stochastics, but made contributions to almost every subarea of
mathematics.
In 1984 he won the most lucrative award in mathematics, the Wolf Prize,
and used all but 720 of the USD 50,000 prize money to establish a
scholarship in his parents’ memory in Israel.
\end{document}
By default, LaTeX will justify paragraphs: whitespace is adjusted to
spread the words uniformly over the line so that the paragraphs fill the
entire width of the page. LaTeX will break words if needed. Every
language has its own rules for hyphenation. The correct rules are loaded
by the babel
package.
Remember also that the default paragraph break in LaTeX is to start a new line, with no empty line in between, and indent this. You can use the package parskip
to change this to a new line with an empty line in between and no indentation.
\usepackage[dutch]{babel}
\usepackage{parskip}
A non-breaking space is a space which cannot be enlarged and where a
sentence won’t break. A non-breaking space (or tie) can be added using
~
. One uses this mostly in references:
Chapter~12
Theorem~1.2
Bartel~Leendert van~der~Waerden
Charles~XII
From 0 to~1
“Ties”—denoted by ‘~’ in plain TeX—are the key to successful line breaking. Once you learn how to insert them, you will have graduated from the ranks of ordinary TeXnical typists to the select group of Distinguished TeXnicians. And it’s really not difficult to train yourself to insert occasional ties, almost without thinking, as you type a manuscript. – Donald Knuth
LaTeX inserts more whitespace after the end of a sentence than it does
between two words. The reason is that this looks good when the text is
justified. However, this could cause problems when there is a period in
the middle of a sentence; LaTeX thinks the sentence ends and adds more
whitespace. To solve this you can use \␣
, a backslash followed by a
space.
The numbers 2, 3, 5, 7, etc.\ are interesting.
If you want to prevent LaTeX from breaking the line after the period,
you can use ~
instead of \␣
.
With \-
you can manually suggest where to break a line in a word. For
example
type\-set\-ting
Here, the line can only be broken at places with a \-
. This is useful
for words with special characters, since LaTeX doesn’t break these
automatically. The same holds for words containing a dash. You should
only use this when a word is split incorrectly. Many words will be
hyphenated in the right way by the babel
package.
Recall that we prefer to determine the layout of our text by structuring it with commands and environments. We will discuss a few important examples.
Words should be emphasised with the command \emph
. Usually emphasised
text appears in italics, but this can be changed. It is considered bad
practise to use commands like \textit
, since LaTeX code is meant for
content and not for layout.
This is important.
This is important.
This is \emph{important}.
\emph{This is \emph{important}.}
Lists can be made using the itemize
environment and the enumerate
environment.
\begin{itemize}
\item Green
\item Yellow
\item Pink
\end{itemize}
In LaTeX it is very easy to number the elements of your list.
\begin{enumerate}
\item Green
\item Yellow
\item Pink
\end{enumerate}
If you want to create lists indexed by letters or Roman numerals instead
of numbers, you can load the package enumitem
, you can find the documentation for this package here at the LaTeX package database CTAN.
The verbatim
environment makes sure text is typeset literally, that
is, LaTeX will ignore any commands in the text. The text also gets a
monospaced typewriter font so it can be used to typeset computer code:
\begin{verbatim}
def gcd(a,b):
"""
Euclides' algorithm.
"""
while a:
a, b = b%a, a
return b
\end{verbatim}
You can insert a code snippet inline using \verb
.
You can set the author with \verb![](\author)!.
The first character after \verb
determines where \verb
stops. Hence
a different character from !
works too.
The hyperref
package provides the command \url
to create hyperlinks.
You can load hyperref
using
\usepackage[hidelinks]{hyperref}
A hyperlink can be made using
\url{http://www.ctan.org}
or
\href{http://www.ctan.org}{CTAN}
There are three standard environments for quotations.
quote
quotation
verse
\\
.enumerate
and
itemize
. Don’t number the lists yourself! (You don’t have to reproduce the specific dots).