Two Parts of a Project

Preamble and document

A LaTeX project has two main parts - the preamble and the document. To successfully typeset anything in LaTeX, we will have to edit both of these parts.

The document contains all of the information that will appear when the project is exported as a PDF. The document is found between the commands \begin{document} and \end{document}.

The preamble gives background information to build the document. Nothing in the preamble will appear when the project is exported as a PDF. The preamble is everything that appears before the command \begin{document}.

Our Blank Project from Overleaf already has some content in both the preamble and document areas.

Lines 1 through 7 (highlighted in pink) contain the preamble.

Lines 8 through 14 (highlighted in blue) contain the document.

Overleaf's LaTeX editor. The document, between the begin document and end document commands, is highlighted in blue. The preamble, everything before the begin document command, is highlighted in pink.

Beginning and ending the document

The begin and end commands are always tied together.

Note that commands \begin{document} and \end{document} are matched. Both must be present in order for the document to compile.

Try deleting either one of them. Overleaf will immediately show a red warning message.

In general, commands of the form \begin{} and \end{} define an environment. We will see another type of environment later in this tutorial. In general, we can never have a \begin{} command without a matching \end{} command, or vice versa.

What goes in the preamble?

When using a word processor, there are some things you might take care of before even beginning to type - setting up the margins and page layout, installing a certain typeface, specifying styles for the headers and the body, and so on. The commands corresponding to actions like this all belong in the preamble.

Let's look at the preamble of our Blank Project.

As previously noted, the command \documentclass{article} sets our document as an "article," which lets us add elements like sections and subsections.

Overleaf also adds the command \usepackage[utf8]{inputenc}. This signals that the text we input will be encoded with UTF-8 (Unicode Transformation Format - 8 bits). In order for computers to process text, every character has to be converted to binary. UTF-8 is one system for making this conversion, and it is the most common one in use on the web. Basically, this means that we can type as we normally would, and the computer will process it properly.

This command, \usepackage{}, can take many different parameters, which we will learn about on the next page. In a typical preamble, \usepackage{} will appear quite a few times.

There are also more specialized commands that might be found in the preamble.

For example, Overleaf automatically added the commands \title{}, \author{}, and \date{}. These commands in the preamble are tied to the command \maketitle in the document. The title, author, and date are background information in the preamble, while \maketitle formats and prints that information in the document.

Exercise 2.2.1

In the preamble of your project on Overleaf, set your name as the author and today's date as the date. Then, compile the preview.

Solution 2.2.1

The \maketitle command in the document should have made the correct title, author, and date appear in the preview.

For example, the code

\title{Blank Project}

\author{Your Name}

\date{August 1, 2021}

Should result in

Blank Project

Your Name

August 1, 2021

at the top of the preview.

If any of these items are incorrect, go back and review the information in the preamble.

On the next page we will look more closely at the command most commonly found in the preamble, \usepackage{}.