2 The Structure of a LaTeX Document

2.1 LaTeX Commands

In LaTeX commands are usually prefixed with a backslash, "\". Some commands have different options that you can specify when you type the command - these options are called "arguments".

Optional arguments (things you can choose to tell the command) usually go inside square brackets [ and ], and mandatory arguments (things you have to tell the command) usually go inside curly braces { and }.

2.2 LaTeX Document Structure

Every LaTeX document starts by defining what kind of document this is going to be, and this section of the document is called the preamble. We do this with the \documentclass command, e.g.

\documentclass[a4paper,11pt]{book}

The standard classes are article, report, book, letter, and slides though you can define your own, and most journals have their own class file (class files have the extension .cls). We shall be concentrating on the three most useful classes to scientific writing: article, report and book.

The \documentclass command also has a number of optional arguments, including:

Multiple options may be separated by commas, but don't put spaces in.

After the preamble comes the main body of the document, and this is enclosed by the \begin{document}...\end{document} commands. This is where the bulk of the information is contained; within this region all of your text, equations, images, tables and lists are described.

2.3 Environments

The \begin{document}...\end{document} LaTeX commands are an example of an environment. Environments are always entered with a \begin{} command and exited via a \end{} command. They define particular typesetting features so that you can set out different parts of your document in different ways, according to its content and purpose.

2.4 Commenting LaTeX

As with all computer code, it is important to ensure your LaTeX is well commented. Whilst simple documents can be self-explanatory, LaTeX documents have a tendency to grow in an organic fashion rather than remaining well-structured documents and this can lead to confusing source code. Not only that, but you may forget what certain LaTeX definitions or commands are and do, or why you used them instead of others.

In LaTeX anything after a percentage sign "%" is treated as a comment, and will not appear in your document.

Summary


Previous page Next page