About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Latest news 2019-11-04: The giveaway of two signed copies of “Quack, quack, quack. Give my hat back!” has closed and the winning entrants have been selected. Thank you to everyone who took part.


2.6 Commands

A command is used to tell LaTeX to do a particular thing at that point in the document. These are the basic forms a command can take:

  1. A Control Word.

    This is a backslash \ followed by letters (A,...,Z,a,...,z). [Commands gobble following space]There can be no non-alphabetical characters in the command, apart from the initial backslash, and the name is always case-sensitive so, for example, \gamma and \Gamma have different meanings. One command that often trips up new users is \LaTeX, which prints the LaTeX logo: LaTeX logo . This command has three captial letters and two lower case letters. If you get the case of any of the letters incorrect, you will get an “undefined control sequence” error.

    There must be no space between the backslash and the start of the command name. Some command names are made up of two or more names joined together, such as \tableofcontents. Make sure you don't insert any spaces in the control word. This will either lead to an error or an unexpected result. For example,

    \appendixname
    displays “Appendix” but

    \appendix name
    switches to the appendices and then prints the word “name”.

    Most LaTeX commands have fairly self-explanatory names. (For example, \chapter starts a new chapter and \rightarrow prints an arrow pointing to the right.) However, in most cases, you need to use U.S. spelling (for example, \color rather than \colour).

    This is the most common form of command. Any spaces immediately following a command of this type are ignored, so for example

    \TeX nician

    will produce

    TeXnician (where the TeX logo is written with a dropped E)

    whereas

    \TeX{} nician

    will produce

    TeX nician (where the TeX logo is written with a dropped E)

    But the following will cause an “undefined control sequence” error:

    \TeXnician

    There is one command that you must use in every document you create, and that is the \documentclass command. This command must be placed at the very start of your document, and indicates what type of document you are creating. This command is described in more detail later.

  2. A Starred Command

    Some commands have variants that are indicated by an asterisk at the end of the name. For example, \chapter makes a numbered chapter whereas \chapter* is makes an unnumbered chapter. A starred command is the version of the command with the asterisk. (On a UK keyboard the asterisk character is usually located on the same key as the digit 8.)

    This may seem like a different form to a control word, described above. After all, I've just said that a control word can only contain alphabetical characters. However a starred command is actually a control word (such as \chapter) followed by an asterisk. The control word checks to see if the next character is an asterisk. If it is, it performs one action, otherwise it performs another action.

    This type should therefore just come under the previous category, but as you will often hear of “starred commands” it seemed better to have a separate category.

  3. A Control Symbol.

    This is a backslash followed by a single non-alphabetical character. For example \% will print a percent symbol. Spaces are not ignored after this type of command, for example

    17.5\% VAT

    will produce

    It's also possible to have starred forms of control symbols. For example \\ forces a line break. If it's not followed by an asterisk a page break is allowed at that line break, but if it is followed by an asterisk \\* no page break is allowed at that line break. (If a page break is needed, it will be made at the end of the previous line instead.)

  4. Character Sequence.

    Some special sequences of characters combine to form an instruction. For example ffi is the command to produce the ffi ligature, and the sequence of symbols !` is the command to produce the upside down exclamation mark ¡

  5. An Internal Command.

    This is like the first type, a control word, but the @ character appears in the command name (for example \c@section) however internal commands should only be used in class files or packages. The @ symbol takes on a special meaning when a file is included using \documentclass (a class file) or \usepackage (a package).

    For example, in a class file or package \c@section is an internal representation of the section counter, whereas in a .tex file \c@section is interpreted as the command \c (the cedilla accent command) that takes the character @ as its argument, followed by section, which produces the rather odd looking @ with a cedilla section [\@ and @ in macro names].

    Don't be tempted to use internal commands until you have first grasped the basics. You have been warned!


This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-00-5).

© 2012 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs