Syntax rules

A LaTeX source file is ordinary running text with commands embedded in it. The commands, the whitespace, and the comments follow a small set of rules that, once internalized, save you from a lifetime of small surprises. Why does writing \LaTeX is eat the space? Why does pressing Enter twice start a new paragraph? This page gathers those mechanics in one place.

Text versus commands

Most of a source file is running text — ordinary characters that are set as-is. Type Hello and you get Hello. By contrast, a command is an instruction to the typesetter — a line break, a heading, a change of font — and it always begins with a **backslash \** (which may appear as a yen sign ¥ in some Japanese setups). \LaTeX means the logo and \newpage means a page break; neither prints as literal text.

The name following the backslash is called a control sequence, and there are two kinds. A control word is \ followed by only letters (A–Z, a–z); a control symbol is \ followed by a single non-letter. So \section, \LaTeX, and \newpage are control words, while \$, \%, \&, and \ (backslash-space) are control symbols. The two differ not only in how their names are delimited but also in how they treat the space that follows (next section).

Why does the distinction matter? A control word’s name ends automatically at the first non-letter, so writing \LaTeXlogo is read as a single (undefined) command named \LaTeXlogo. To stop the name at \LaTeX, you must follow it with a non-letter — a space, a symbol, or {}. A control symbol, being exactly one character long, has no such issue: \$5 reads cleanly as the dollar sign followed by 5.

Control words swallow the following space

This is the single biggest trap. All whitespace immediately after a control word — spaces, tabs, newlines — is discarded. It serves only to delimit the name and produces no space in the output. So \LaTeX is great loses the space between \LaTeX and is, and you get the run-together “LaTeXis great.”

There are three standard fixes. (1) Empty braces: \LaTeX{} is — the {} ends the name and the ordinary space survives. (2) The control space: \LaTeX\ is\ (a backslash followed by a space) forces exactly one normal interword space. (3) Wrap the command in braces: {\LaTeX} is. All three yield the same “LaTeX is.” When in doubt, {} is the safe choice — it works whether the next character is a space or some other non-letter.

latex
% 制御語の直後の空白は消える / The space after a control word vanishes:
\LaTeX is great      % → LaTeXis great   (まちがい / wrong)

% 直し方 / The fixes — all give “LaTeX is great”:
\LaTeX{} is great
\LaTeX\ is great
{\LaTeX} is great

By contrast, a control symbol does not eat the following space — the blank after \$ survives as a normal interword space. The control space \ is also used beyond cleaning up after commands: after a period that marks an abbreviation, as in Prof.\ Smith or et al.\ (1993). Because LaTeX adds slightly extra space after a sentence-ending period by default, \ tells it “this is not the end of a sentence,” keeping the interword spacing even.

Arguments and grouping with braces

Many commands take arguments, and there are two kinds: **curly braces { } enclose a mandatory argument, while square brackets [ ] enclose an optional one**. In \section{Introduction}, the {Introduction} is the required heading text; in \documentclass[12pt]{article}, the [12pt] is optional and {article} is the mandatory class name. The usual shape is \command[options]{required}.

Braces { } also have a second role: grouping — limiting the scope of a declaration. Declaration-form commands that change font or size — \bfseries (bold), \itshape (italic), \large (larger), and the like — take no argument and instead affect “everything from here on.” Wrap them in braces and the effect is confined to just that group: {\bfseries bold} normal makes only “bold” bold, and the closing } reverts to the previous setting.

latex
\section{はじめに}                 % 必須引数 / mandatory argument
\documentclass[12pt]{article}     % [オプション]{必須} / [optional]{required}

{\bfseries 太字になる} ここは普通   % {} で効果を閉じ込める / braces limit the scope
{\bfseries bold here} back to normal

Inside and outside a group are independent, so a visual change never leaks into territory you did not intend. This is the same idea behind environments (\begin{...}...\end{...}): a \begin\end pair also forms a group. Environments are covered in detail on their own page.

Spaces, line breaks, and blank lines

Whitespace follows distinctive rules that decouple how the source looks from how the output reads. First, any run of consecutive blanks (spaces or tabs) collapses into a single interword space — one space or ten between words produces the same result. Second, a single newline in the source is treated as just a space. Wherever you wrap a line, LaTeX decides the final line breaks itself, so you are free to break the source at a comfortable width.

So how do you start a new paragraph? With a blank line — leaving one empty line marks a paragraph break. Two or more consecutive blank lines do the same thing as one: a single paragraph break. Conversely, merely breaking a line in the source does *not* start a new paragraph. Finer control over line and paragraph breaks (such as forcing a break with \\) is covered on the line-and-paragraph-breaks page.

document.tex
これらの    余分な空白は     1 つにまとめられ、
この改行も空白 1 つになります。

空行をはさむと、ここから新しい段落が始まります。

Sometimes you want to place an interword space exactly where you mean it. The classic case is the **tie ~ — a non-breaking space** that you insert where a line must not split, as in Fig.~\ref{fig:1}, Chapter~12, or Donald~E. Knuth. It is the width of a normal interword space, but no break can occur there. The **control space \ , as above, forces a normal-width space, and in math mode \, (a thin space, 3/18 of a quad)** lets you fine-tune the spacing.

Comments

A **percent sign % begins a comment that runs to the end of that line, and the comment is ignored entirely at compile time. Because it never appears in the output, use it to leave notes in your source or to temporarily disable (“comment out”) a command. A comment not only extends to the end of the line — it also swallows that line’s newline (and any trailing spaces).** That turns out to be a handy trick.

Remember that a newline in the source becomes a space. When you want to break a long word across several source lines without introducing a stray space at the seam, end the line with %: the newline disappears and the next line joins on with no space. The same trick prevents unwanted spaces when you split a command across lines.

latex
これは行末コメント % ここから行末まで(と改行)が無視される / ignored to end of line

超長い%
単語          % → 「超長い単語」 % で改行を消してつなぐ / % joins the lines, no space

割引率は 100\% です。   % 文字としての % は \% と書く / a literal percent is \%

Note that % is itself a special character, so **to print a literal percent sign you write \%** (which, being a control symbol, does not eat the following space). The full set of special characters is collected on the special-characters page.

To disable several lines at once, instead of prefixing each with %, you have two options. Wrap the block in the **comment environment** provided by the verbatim package (or the comment package) — \begin{comment} … \end{comment} — or wrap it in **\iffalse … \fi**, which uses a TeX conditional. The latter needs no extra package and lets you comment out an entire block in one stroke.

latex
\usepackage{verbatim}            % プリアンブルで / in the preamble

\begin{comment}
このブロックは丸ごと無視される。
This whole block is ignored.
\end{comment}

\iffalse
下書きのコードもパッケージ無しで一括コメントアウト。
Draft code, commented out with no package needed.
\fi