Your support for our advertisers helps cover the cost of hosting, research, and maintenance of this document

Formatting Information — An introduction to typesetting with LATEX

Chapter 1: Writing documents

Section 1.4: LATEX commands

Now that you have seen LATEX working, let’s have a closer look at what it’s actually doing. LATEX commands all begin with a backslash (\) and normally consist of lowercase letters only (there are a few which have uppercase letters). Going through the quickstart.tex document in Figure 1.2, we can see the following commands being used:

\documentclass

specifies the class of document (article) and the size of type for the text (12pt)

\usepackage

tells LATEX to use the named packages (plugins), here palatino (a font) and url (provides a way to format URIs)

\setcounter

sets the value of a counter, here secnumdepth, to a value, here zero, which in this case prevents sections being numbered)

\begin

marks the beginning of an environment, here document, which contains the whole text of the document. It’s terminated by a matching \end{document} command further down.

Everything up to this point has been a preamble, setting up how the document looks;

\section

identifies a section heading;

\LaTeX

typesets the LATEX logo;

\today

typesets today’s date;

\begin

marks the beginning of an itemize environment, which is an itemized (bulleted) list. It’s terminated by a matching \end{itemize} command at the end of the list;

\item

marks the start of a new list item;

\end

ends an environment, here the itemized list;

\subsection

identifies a subsection heading;

\url

typesets a URI, allowing line-breaks only at slashes or dots;

\begin

begins another environment, center, which centres the material;

\fbox

typesets the material in curly braces in a framed box;

\textit

typesets the material in curly braces in italic type;

\end

ends the center environment;

\end{document}

ends the document environment, and thereby terminates the document.

Backslashes and forward slashes

Do not confuse the backslash (\) with the forward slash (/). They are two different characters.

  • The forward slash is used in Unix-based systems (including Mac OS X and GNU/Linux) to separate directory names and file names;

  • The forward slash is also used on the Web to separate the directory names and file names in a URI;

  • The backslash is used to separate directory names and file names in the Microsoft Windows file system only.

The backslash is used to signal the start of a LATEX command in all systems, and when you refer to directory and file names in LATEX (eg image files), you MUST use the forward slash, even in Microsoft Windows.

1.4.1 Simple commands

Simple commands are just the command name on its own, after the backslash, for example:

\today
	

This example is an instruction to LATEX to insert the current date at that point. You would usually use this in a draft article or report somewhere close to the beginning, so that you have a record of when it was last typeset. You don’t have to do anything else, although there are packages for changing the format of the date.

You will also come across several font-changing commands like \sffamily (switches to the sans-serif font family); \bfseries (switches to the boldface font series); \Large (steps up to the Large size of type); but you should wait until you have gone through Chapter 6 ‘Layouts and fonts’ before trying to use them, as there are other forms of the commands more suited to textual use.

1.4.2 Commands with arguments

Most LATEX commands are followed by one or more arguments, meaning information to be acted upon. Here are two examples, a chapter title (see § 2.6) and a cross-reference label (see § 5.3.1):

\chapter{Poetic Form} \label{pform} The shape of poetry 
when written or printed distinguishes it from prose.
        

Such arguments always go in { curly braces} like those shown above. Be careful not to confuse the curly braces on your keyboard with (round) parentheses, [square] brackets, <less-than or greater-than> signs, 〈angled〉 brackets, or «guillemets» (French quotes, not guillemots; those are sea-birds). They are all quite different and they mean different things, as shown.

  1. Embarrassingly, the LATEX command for guillemets was mis-spelled guillemot when it was created, and no-one seems to have the nerve to change it. Albatross!