Syntax rules

Type \LaTeX is great and what comes out is “LaTeXis great”. A space has gone missing, and not one line of error was printed. It is not a bug: TeX threw that space away on purpose. Every syntax rule in LaTeX — where a command name ends, how spaces and line breaks are folded up, what a % comment actually deletes — follows from a single thing, the way TeX reads your source one line at a time. This page follows that reading process and disposes of the three mines every beginner steps on — the space that vanishes, the space that appears, and the font change that will not stop — from the mechanism rather than the symptom.

Where a command ends: control words and control symbols

A command name ends at the first character that is not a letter. Most of a source file is running text that gets set as it stands, but the moment a backslash \ appears (it may show as a yen sign ¥ in some Japanese setups), TeX switches modes and starts reading a name. There are exactly two ways it can take that name. A control word is \ followed by letters only (A–Z, a–z); a control symbol is \ followed by a single non-letter. So \section, \LaTeX and \newpage are the former, while \$, \%, \& and \ (backslash-space) are the latter.

The distinction is not word-play: it changes the symptom when you get it wrong. A control word's name keeps growing as long as letters keep coming, so \LaTeXlogo is not read as \LaTeX plus logo — it is read as one name, \LaTeXlogo, which does not exist, and the run stops with ! Undefined control sequence. To follow the logo with letters you have to cut the name short with something that is not a letter: a space, a symbol, or {}. A control symbol, by contrast, is settled after one character and cannot grow, so \$5 reads plainly as a dollar sign followed by 5. That one-character-only nature is exactly why \$ and \% stay safe when a digit or symbol comes right after them.

latex
% A control word is letters only; its name stops at the first non-letter.
\LaTeX        % the logo
\LaTeXlogo    % ! Undefined control sequence. -- read as ONE name

% A control symbol is exactly one non-letter after the backslash.
\$ \% \& \_   % the literal characters $ % & _
\,            % a thin space

Why \LaTeX is prints “LaTeXis”

Every blank immediately after a control word is skipped, however many there are. The whitespace is consumed as the signal that the name has ended, and not a scrap of it survives into the output. That is why \LaTeX is great comes out as “LaTeXis great”. The part people miss is that spaces are not the only casualty: tabs go the same way, and so does the line break. Fold the source after \LaTeX and put is great on the next line for readability, and nothing changes. The place where “but I typed a space” counts for least is precisely the spot right after a command.

There are three standard fixes, and all three give the same “LaTeX is great”. (1) Empty braces, \LaTeX{} is{} is not a letter, so the name ends there and the following space survives as an ordinary interword space. (2) The control space, \LaTeX\ is\ (backslash plus space) is the command meaning “put one interword space here”. (3) Wrap the command in braces, {\LaTeX} is. In practice (1) is the safe default: it behaves the same whether a space or a symbol follows, and it does not break when you edit the sentence later. Because this vanishing space bites hardest in commands you define yourself, the tools bundle ships the xspace package (by David Carlisle and others). Put \xspace at the end of a definition and it supplies the space only when the next character is not punctuation.

latex
\LaTeX is great        % -> LaTeXis great   (the space is eaten)

\LaTeX{} is great      % -> LaTeX is great
\LaTeX\ is great       % -> LaTeX is great
{\LaTeX} is great      % -> LaTeX is great

% In your own macros, let xspace decide:
\usepackage{xspace}
\newcommand{\myTeX}{\LaTeX\xspace}
\myTeX is great, and \myTeX, and \myTeX.  % space added, then not, then not

A control symbol, by contrast, does not eat the space after it: write \$ 5 and an interword space remains between the dollar sign and the 5. That points at the other job of \ . LaTeX puts slightly extra space after a sentence-ending period by default, so a period that merely marks an abbreviationProf. Smith, et al. (1993) — gets stretched along with it. Writing Prof.\ Smith and et al.\ (1993) tells LaTeX “this is not the end of a sentence” and keeps the interword spacing even. For the opposite need — “do not break the line here” — use the tie ~. The ~ in Fig.~1, Chapter~12 or Donald~E. Knuth is the width of a normal interword space, but a line can never break at it. For fine adjustment there is \, (a thin space): \thinmuskip, that is 3 mu or one sixth of an em, in math, and 0.16667 em in text — the same width either way.

The two jobs of curly braces: passing arguments and fencing scope

Curly braces { } enclose a mandatory argument; square brackets [ ] enclose an optional one. The order is normally \command[options]{required}: in \section{Introduction} the {Introduction} is the required heading text, while in \documentclass[12pt]{article} the [12pt] is optional and {article} is the mandatory class name. There are places where a one-character argument can go without braces, but leaving them in is safer. The moment you add a word later, an unbraced argument breaks in one of two ways: it swallows the neighbouring character, or it gets swallowed by one.

Braces have a second job: they open a group. The declaration-form commands that change font or size — \bfseries (bold), \itshape (italic), \large (larger) — take no argument at all and simply change “everything from here on”. That is why an unattended one leaves the rest of the document in bold. Wrap it in braces and the effect is fenced inside that group alone; the moment you pass the closing } the previous setting is back. {\bfseries bold here} back to normal and the argument form \textbf{bold here} back to normal give the same result, but the former, because it marks off a region, is what you reach for when several declarations have to apply together.

latex
\section{Introduction}             % {...} = mandatory argument
\documentclass[12pt]{article}     % [...] = optional, {...} = mandatory

{\bfseries bold here} back to normal   % braces fence the declaration in
\textbf{bold here} back to normal      % the argument form does the same

{\large\bfseries several at once} back to normal

This fencing idea is exactly what an environment, \begin{...}\end{...}, is built on. An environment opens a group when it starts and closes it when it ends, so a font change made inside never leaks out. Braces and environments are the same tool at different scales; the environments page takes it from there.

How spaces, line breaks, and blank lines get folded up

Any run of consecutive blanks collapses into one interword space, and a single newline in the source becomes one interword space too. One space between words or ten, or a fold onto the next line — the output is identical. Far from being an inconvenience, this is the design's hinge: because LaTeX alone decides where lines break, justification and hyphenation can work at all. The upshot for you is that the source may be wrapped at whatever width you like, and version-control diffs can be kept to one readable sentence per line.

So how do you change paragraphs? With a blank line. Leave one empty line and that is the paragraph break; two or more in a row still count as a single break. There is a subtlety here that is easy to miss: a line containing nothing but spaces counts as a blank line too. TeX discards the trailing whitespace of every input line before reading it, so a line holding only spaces becomes a line holding nothing. When a paragraph breaks where it should not, or refuses to break where it should, suspect exactly that line — the one your editor renders indistinguishably from an empty one. Paragraph handling proper (\par, \parindent) belongs to the line-and-paragraph-breaks page.

latex
These     extra   spaces    collapse into one,
and this newline becomes a single space too.

A blank line -- and only a blank line -- starts a new paragraph.


Two blank lines do exactly what one does.

% removes the rest of the line — and the line break with it

From % to the end of that line is a comment and is ignored entirely at typesetting time — and what disappears is not only the rest of the line but the line break itself. Leaving notes and temporarily disabling a command are the obvious uses, but that swallowed newline is what created the other main use of %. As the previous section showed, a newline in the source becomes one space. So when all you want is to fold a long word or a long command across source lines, the fold itself injects a space you did not ask for. End the line with % and no such space appears: the next line joins on flush. Better still, the line that begins after a % has its leading whitespace skipped as well, so you may indent the continuation line as much as you like. The source stays readable while the output stays one word.

latex
Visible text % from here to the end of the line is dropped, newline included

Anti%
        disestablishmentarianism   % -> one word: the indent is dropped too

\newcommand{\courseTitle}{%
  Advanced Topics in \LaTeX%
}                                  % no stray space at either seam

The rate was 100\% last year.      % a literal percent sign is \%

One caution: % is itself a special character, so to print a literal percent sign you write \%. Forget it and the whole rest of that line disappears — with no error and no warning, half a sentence simply goes missing from the PDF, which makes it one of the nastiest symptoms in the language. Being a control symbol, \% does not eat the space that follows it. How to escape the other special characters (#, $, &, _, {, }, ~, ^, \) is collected on the special-characters page.

To disable several lines at once, there are two alternatives to prefixing each with %. Wrap the block in the comment environment supplied by the verbatim package (or by the comment package), \begin{comment} … \end{comment}, or wrap it in \iffalse … \fi, which uses a TeX conditional. The latter needs no package and is quick, but TeX still reads what is inside, so an unbalanced \if in the parked text will break it there. To mothball a whole draft, the comment environment is the more predictable choice.

latex
\usepackage{verbatim}   % in the preamble

\begin{comment}
This whole block is ignored.
\end{comment}

\iffalse
Draft text, parked with no package needed.
\fi

What to check when a space vanishes or appears

Split the problem in two by asking whether the symptom came with an error. A run that stops with something like ! Undefined control sequence. points at where a command name ended; output that is merely wrong, with no error and no warning, points at whitespace and comments. That is the order. The second kind gives you no useful line number, so the only way in is to narrow by category. Starting a little before the reported line, check whether a command name has swallowed the letters after it and whether {...} and [...] are balanced; then check whether an end-of-line % removed a space you needed, or whether a literal percent sign was written without its \%.

What you wroteSymptomFix
\LaTeXlogostops with ! Undefined control sequence.End the name with a non-letter, as in \LaTeX{}logo
\LaTeX iswords run together as “LaTeXis”\LaTeX{} is or \LaTeX\ is; in your own macros, \xspace
\bfserieseverything after it stays boldFence it as {\bfseries ...}, or use \textbf{...}
100%the rest of that line silently disappearsA literal percent sign must be written 100\%
(a line of spaces)a paragraph breaks where you did not intendA spaces-only line is a blank line; show invisibles in your editor

Finally, deciding on habits that do not break beats memorising the rules. Cut a command name with {} when letters follow. Fence semantic units in {...}. Fold long definitions across lines with an end-of-line % instead of packing them into one. And do not let commented-out old drafts accumulate in the .tex — leave the versions you want to compare to a history tool like Git and keep only what you intend to typeset, so that error line numbers line up with the real manuscript and debugging gets faster. Those four habits head off most of the early stumbles.