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: White-space in LATEX

In LATEX documents, all multiple consecutive spaces and TAB characters are treated as if they were a single space during typesetting. All multiple newlines (linebreaks) are treated as if they were just two newlines (a paragraph break).

LATEX does its own spacing and alignment using the commands you give it and the layout in the stylesheet, so you have extremely precise control. You are therefore free to use extra white-space in your editor for optical ease and convenience when editing.

1.5.1 Swallowing space after commands

Rule: LATEX discards any white-space after a command ending in a letter when there is no argument present.

It does this automatically, so that you don’t get unwanted extra space in your typeset output, but it does mean that any simple command which ends in a letter and has no argument MUST be followed by white-space or an empty pair of curly braces before the text which follows it, to keep it separate. Read that again.

\tableofcontents Thanks to Aunt Mabel for all her 
help with this book.

\tableofcontents	Thanks to Aunt Mabel for 
all her help with this book.

\tableofcontents
Thanks to Aunt Mabel for her help with this book.

\tableofcontents{}Thanks to Aunt Mabel for all her 
help with this book.
	

The additional spacing or braces is not needed if the command name ends with a non-letter, or is directly followed by another command, or occurs immediately before a closing curly-brace, or is followed by a double newline (paragraph break). Read that again, too.

Simple one-word commands (like \tableofcontents) MUST therefore be separated from any following text with curly braces or white-space, which means a normal space or a newline (linebreak) or a TAB character. If you forget the white-space, like this:

\tableofcontentsThanks to Aunt Mabel for all her 
help with this book.
	

then LATEX will treat everything up to the next space as a command, and end up trying to make sense of a ‘command’ apparently called \tableofcontentsThanks. There’s no such command, of course, so LATEX will complain by displaying an error message (see § C.3.3.2).

With commands that take arguments you do not need to use extra white-space or curly braces after the command, because the existing curly braces will keep the command separate from any normal text which comes after it. The following example is therefore exactly equivalent to the one we just saw in § 1.4.2, and will typeset identically despite the absence of spaces between commands.

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

By the same token, the following example is therefore also exactly equivalent (although rather unusual!):

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

That is, it will get typeset exactly the same.

Why would you want such odd spacing (or none)? The answer is usually never, although extra blank lines in your editor between chapters or sections make editing easier. But a lot of LATEX is not typed by hand: it is generated by computer programs from other systems such as web scripts, XML documents, databases, filestores, mashup engines and other processes, and it makes life easier for the programmers if they don’t have to worry about the odd space or two creeping in here and there in normal text: it simply won’t have any effect. It also means that if you want to use extra spacing to make your text easier to edit, you don’t have to worry about unwanted linebreaks coming out between sections or paragraphs, tabbing in tables, or indentation in list items.