This lesson is about the structure of a LaTeX file.

## A LaTeX document

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}.

### Document classes

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

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.

### Top matter

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}


### Exercise 1

1. Writing as little code as possible, create a Dutch document with title “Een bewijs van de Riemannhypothese” with yourself as the author.
2. Make sure LaTeX typesets the date in Dutch and not in English.

### Important

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 seperating layout and content

• We can focus on the content.
• We obtain a consistent layout.
• We (or a publisher) are able to change the layout easily.

## Structuring text

In LaTeX we have groups, commands and environments to structure our document.

### Groups

A group is a block of code surrounded by { and }. A group indicates that the code belongs together.

### Commands

Examples of commands are \documentclass, \usepackage and \author. A command comes in one of these two types:

• First a \ and then a name consisting only of letters. After the name a space, a number or a special character follows.
• First a \ and then a number or a special character.

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}...


### Environments

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.

### Exercise 2

In this assignment we will define our own command.

1. Create a new LaTeX file using the mathtools package and put the following in the preamble:

\newcommand{\R}{\mathbb{R}}


The real line $\R{}$.

3. What happens if you remove the empty group {}?

4. We will now create a command with an argument. Put the following in the preamble:

\newcommand{\Bb}[1]{\mathbb{#1}}

5. Test it using this code:

The rationals $\Bb{Q}$.

6. 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.

### Remember

• What is the global structure of a LaTeX file?
• What do \documentclass, \usepackage, \title, \author, \and, \date and \maketitle do?
• What does the babel-package do?
• Why do we seperate layout and content?
• What are groups, commands and environments?
• How do you make your own command?
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9899670481681824, "perplexity": 2599.6551684652795}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2018-51/segments/1544376828448.76/warc/CC-MAIN-20181217065106-20181217091106-00606.warc.gz"}