This lesson is about the structure of a LaTeX file.
Every LaTeX document has the following structure:
\documentclass[a4paper]{article}
\begin{document}
\end{document}
In this, article
can be replaced by a different document class. The
part before \begin{document}
is called the preamble.
The preamble contains commands which influence the entire document. For
example, packages are loaded here. The actual text of your document is
between \begin{document}
and \end{document}
.
A document class is a collection of settings corresponding to a specific type of document. The document class is set with
\documentclass[options]{class}
where options
is a list of options seperated by commas. Later, we will
look further into this.
Packages are extensions of LaTeX that add functionality. One can think of the possibility to add figures or additional commands for mathematical symbols. Modern TeX distributions (see Installing LaTeX) contain many packages, which can be used by putting
\usepackage[options]{packagename}
in the preamble, with packagename
the name of the package and
options
a list of options. A package which is indispensible in Dutch
documents is
\usepackage[dutch]{babel}
The babel
package with the option dutch
will make sure that LaTeX
replaces standard titles such as Chapter and Table of contents by
the Dutch equivalents Hoofdstuk and Inhoudsopgave respectively. The
package also configures hyphenation so it is essential to use the right
language option.
The preamble is followed by the document environment, beginning with
\begin{document}
and ending with \end{document}
. In the first lines
of the document environment one gives information about the document
itself, such as the name of the author, the title and the date. This is
called top matter. With the command \maketitle
LaTeX will typeset
the topmatter following the style of the document class. An example of
top matter is
\title{A new proof of an old theorem}
\author{Jane Doe}
\maketitle
A date can be inserted with \date{January 1st, 2017}
. If you don’t use
\date
, LaTeX will typeset the current date. More than one author can
be typeset with \and
:
\author{Jane Doe \and John Doe}
Note that it is also correct to define the title, author, date, etc. using commands such as \title{}
in the preamble. It is then only necessary to include the command \maketitle
in the topmatter.
We see that LaTeX determines the layout itself. This is an important concept in LaTeX! We determine the layout of the text by structuring it. By separating layout and content
In LaTeX we have groups, commands and environments to structure our document.
A group is a block of code surrounded by {
and }
. A group
indicates that the code belongs together.
Examples of commands are \documentclass
, \usepackage
and \author
.
The name of a command is case sensitive. Some commands require one or
more arguments, which are written between {
and }
after the command.
An argument can be optional, which is indicated by [
and ]
after the
command. The general syntax is:
\commandname[option1,option2,...]{argument1}{argument2}...
An environment such as document
is created by two commands:
\begin{name}
\end{name}
Inside an environment one can write LaTeX code. An environment defines a group automatically.
In this assignment we will define our own command.
Create a new LaTeX file using the amssymb package and put the following in the preamble:
\newcommand{\R}{\mathbb{R}}
Test your new command:
The real line $\R{}$.
What happens if you remove the empty group {}
?
We will now create a command with an argument. Put the following in the preamble:
\newcommand{\Bb}[1]{\mathbb{#1}}
Test it using this code:
The rationals $\Bb{Q}$.
With [1]
we indicate that the command expects a single argument.
We use this argument with #1
. Try to make a command with two
arguments.
\documentclass
, \usepackage
, \title
, \author
,
\and
, \date
and \maketitle
do?babel
-package do?