specifies the class of document (article) and the size of type for the text (12pt) and the paper size. There are other options, see § 2.1.3 below;
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.5: LATEX commands
Now that you have seen LATEX working, and hopefully experimented a little with changing some of the commands and packages in quickstart.tex let’s have a closer look at what it’s actually doing.
1.5.1 Simple commands
Simple commands are just the command name on its own, after the backslash. Command names normally consist of lowercase letters only:
\tableofcontents
This example is an instruction to LATEX to insert the Table of Contents at that point. This creates a list of all your chapters, sections, subsections, etc with their page numbers, which are automatically updated each time the document is processed (so a reprocessing is needed to show them: this is normally done automatically by your editor).
Other simple commands include \listoffigures, \listoftables (which work like \tableofcontents); \today which inserts today’s date; and \LaTeX, which creates the LATEX logo.
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 only in the Microsoft Windows file system;
The backslash is used to signal the start of a LATEX command in all systems.
When you refer to directory and file names in LATEX (eg image files), you MUST use the forward slash, even in Microsoft Windows.
1.5.2 Commands with arguments
Most commands, however, need some information to work on, called an argument (grammatical jargon for text to work with), which you put in curly braces after the command name. Here are two examples, a section title (see § 2.6 below) and a cross-reference label (see § 5.3.1 below):
\section{Poetic Form}\label{pform}
The shape of poetry when written or printed
distinguishes it from prose.When an argument is needed (as here) it always goes in
{curly
braces} like those shown
above.
Some commands can have optional
arguments (use them when you need to,
otherwise not). These always go in
[square
brackets] and usually go
before the first compulsory argument.
Here’s an example using \section, which
allows an optional short argument to go in the Table of
Contents when the real title would be too long:
\section[Poetic Form]{The different types of form or layout of poems}This avoids the Table of Contents being cluttered with multi-line headings when short ones will do, but still keeps the long heading in the text.
Warning
Be careful not to confuse the curly braces on your keyboard with (round) parentheses, [square] brackets, <less-than or greater-than> signs, 〈computer angled brackets〉, or «guillemets» (French quotes, not guillemots; those are sea-birds). They are all quite different and they mean different things.
(Embarrassingly, the LATEX command for the French quotation marks was mis-copied as ‘guillemot’ when it was created, apparently from an earlier error by Adobe (Beeton, 2005) and no-one seems to have the nerve to change it. Albatross!)
1.5.3 Commands used in the Quick-Start example
Going through the quickstart.tex document in your editor, you can see the following commands being used:
- \documentclass
- \usepackage
tells LATEX to use the named packages (plugins), here
fontspec to access all your fonts;
graphicx to enable graphics (images) to be included;
metalogo used to get the XƎLATEX logo (you probably don’t need this in your own documents)
biblatex to format bibliographies, here using options for the biber program, author-year type citations, and no special sorting
The \addbibresource command says what the name of the bibliography database is (quickstart.bib gets generated automatically in this example)
The \nocite command with * as the argument means ‘cite everything’. See § 5.3.2 below for details of how to set up your own bibliography for normal citation and reference.
- \setmainfont
sets the main document font, usually for Roman (serif) type. The name given as the argument is the full font name specified in the font itself (see your Fonts folders for all these). The default is Latin Modern Roman;
- \setsansfont
sets the sans-serif font, if you want to use one. The default is Latin Modern Sans.
There is also a \setmonofont to specify the monospace (typewriter-style) font. The default is Latin Modern Mono.
Everything up to this point after the \documentclass command is called the Preamble, where you set up how the document looks, as you have already seen and experimented with.
- \begin
marks the beginning of an environment, a LATEX term for an enclosed region of a document that needs particular formatting. The outermost environment is always called document, as it encloses the whole text, and it’s terminated by a matching \end{document} at the bottom of the file.
There are lots of other environments: they all have a \begin and an \end, and they must nest inside one another with no overlap;
- \title
specifies the title of your document. Some document classes (not the default article) allow a \subtitle as well;
- \LaTeX
typesets the LATEX logo. It ends with a letter, so needs either a backslash-space after it, or an empty pair of curly braces (see the note ‘Four rules for spacing in LATEX documents’ below for why)
- \author
specifies the author[s] of the document (separate multiple authors with \and)
- \date
not used here: if you omit it, it automatically uses today’s date. But you could use this command with a date in curly braces. Many journal classes allow multiple date commands for submission, edits, approval, etc;
- \maketitle
signals that you have entered all the metadata (data about your document), and the title block should be typeset. If you omit this command, you get no title block;
- abstract
is the name of the environment used to identify the Abstract of an article.
Paragraphs are just text with no command or environment. A blank line ends a paragraph and starts a new one.
- \tableofcontents
inserts a Table of Contents at that point. The document has to be reprocessed for it to take effect because the list of chapters or sections gets stored the first time and reused the second time;
- \section
identifies a section heading;
- enumerate
is the environment for a numbered list. It’s terminated by a matching \end{enumerate} command at the end of the list;
- \item
marks the start of a new list item inside a list environment (eg enumerate, itemize, or description)
- \texttt
typesets the argument in the current monospace (typewriter-style) font, used for filenames and other computer features;
- \ref
typesets the reference number for something in the document which has a matching \label command, used for cross-referencing. The argument is the name of the label.
The associated \pageref command typesets the number of the page on which the labelled item has been set;
- figure
is the environment to identify a Figure. It has an optional argument of one or more letters to recommend where on the page it should be placed, if there is room (see § 4.2.1 below)
- \caption
identifies the caption of a Figure or a Table;
- \TeX
typesets the TEX logo (note that in the Figure, the name of the editor is TEXStudio with no space, so there is no need for the backslash-space or curly braces mentioned in item ‘\LaTeX’ above;
- \label
attaches a cross-reference label to the current environment or section. The number gets worked out, and can be used elsewhere with the \ref and \pageref commands (see item ‘\ref’ above)
- center
is an environment which centers its contents between the current margins;
- \includegraphics
includes an external graphics (image) file at this point. The argument is the filename, which must be a JPG, PNG, or one-page PDF image. Optional arguments can be used to specify width, height, and other modifications;
- \subsection
identifies a subsection heading;
- itemize
is an environment identifying a bulleted list. It’s terminated by a matching \end{itemize} command at the end of the list. It contains \items;
- \emph
typesets the argument as emphasis (usually italics). If used inside an environment which is already italicised, it will typeset in upright type;
- \%
typesets the percent sign. You can’t use the percent sign alone because that’s LATEX’s comment character, which makes the rest of the line ignored;
- \url
typesets a URL in a monospace font, allowing line-breaks only at slashes or dots, and never with added hyphens;
- \\
the double-backslash causes a premature line-break, ending the line early in order to fit something else on the following line;
- \textit
typesets the argument in italics regardless of the context;
- \description
is a list environment for a dictionary-style layout, with a keyword followed by the explanation. The keywords go as an optional arguments to the \list commands;
- eqnarray
is an environment for typesetting a multi-line mathematical equation (only used here because the equation is too wide to fit in the margins). The eqnarray* version omits the otherwise automatic equation number.
The mathematical commands are not covered in this book: they are left as an exercise to the interested reader;
- \printbibliography
typesets your bibliography, if there is one.
- filecontents*
is an environment to allow the contents of another file to be stored in your document, and written to the filename named in the argument when the document is processed. An optional argument overwrite allows the file to be silently overwritten each time.
