LaTeX reserves exactly ten special characters — # $ % & ~ _ ^ \ { } — and the list was not chosen by anybody. TeX assigns every character a category code; ordinary characters are “letter” (11) or “other” (12). Exactly ten printable ASCII characters carry some other number, and those ten are the reserved ones. So the answer to “why these ten?” is neither history nor taste: it is the setup table of TeX’s input processor. This page covers how to print each of them literally, how to set accents, and how to type non-ASCII text now that UTF-8 is the LaTeX default.
The ten reserved characters and their category codes
A reserved character is one that LaTeX uses as part of its own syntax, so typing it does not print it — it triggers a behaviour. Type % and the rest of the line disappears; type $ and you switch into math mode; type & and a table column is separated. Restated as category codes: \ is 0 (start a command), { is 1 and } is 2 (open and close a group), $ is 3 (math shift), & is 4 (alignment tab), # is 6 (parameter number), ^ is 7 (superscript), _ is 8 (subscript), ~ is 13 (active character) and % is 14 (comment). a is 11, and 1 or + are 12 — characters that do nothing but print.
What happens when you type one raw differs from character to character. The most dangerous by far is %, which raises no error at all and silently eats the rest of the line. & gives ! Misplaced alignment tab character &.; _ and ^ in body text give ! Missing $ inserted.; } gives ! Too many }'s.; and \ reads whatever follows as a command name and produces ! Undefined control sequence. Only # has an unusual message: it starts ! You can't use and continues macro parameter character #' in horizontal mode. ~ alone raises neither error nor warning — it is quietly set as a non-breaking space.
| Character | Category code | Its job | Typed raw |
|---|---|---|---|
\ | 0 | Begins a command | ! Undefined control sequence. |
{ | 1 | Opens a group or argument | Unclosed, it errors at the end of the file |
} | 2 | Closes a group or argument | ! Too many }'s. |
$ | 3 | Begins and ends math mode | Unbalanced, it gives ! Missing $ inserted. |
& | 4 | Column separator in tables and alignments | ! Misplaced alignment tab character &. |
# | 6 | Argument number in a macro definition (#1, #2, …) | ! You can't use … in horizontal mode. |
^ | 7 | Superscript in math mode | In text it gives ! Missing $ inserted. |
_ | 8 | Subscript in math mode | In text it gives ! Missing $ inserted. |
~ | 13 | Active character; a non-breaking space | No error; it silently becomes a non-breaking space |
% | 14 | Comment; the rest of the line is ignored | No error; the rest of the line silently disappears |
Printing them literally: seven just need escaping
Seven of the ten are easy: put a single backslash in front — \#, \$, \%, \&, \_, \{, \}. Write \$1.23 and you get $1.23. The backslash signals “the next character is itself, not the start of a command”. The machinery is plain, too: inside the kernel, \%, \& and \# are written as \chardef — a definition that says nothing more than “print the character at this slot”. Only \$, \{ and \} check whether they are in math mode and adapt, which is why the same spelling also works inside a formula.
| You type | You get | Notes |
|---|---|---|
\# | # | A single backslash in front |
\$ | $ | Works inside math mode as well |
\% | % | For percentages, as in 50\% |
\& | & | For the ampersand in company and title names |
\_ | _ | In the default encoding it is drawn as a rule, not a glyph |
\{ | { | Works inside math mode as well |
\} | } | Works inside math mode as well |
\textasciitilde | ~ | \~{} does the same; a bare \~ is an accent command |
\textasciicircum | ^ | \^{} does the same; a bare \^ is an accent command |
\textbackslash | \ | \\ is the line-break command and prints nothing |
The awkward three: tilde, caret and backslash
Only ~, ^ and \ need more than an escape, and the reason is simple: the escaped form already means something else. \~ and \^ are accent commands that place a tilde or a hat over the next letter — \~n gives ñ, \^o gives ô. When you want the mark on its own, hand the accent an empty argument so it has nothing to sit on: \~{} and \^{}. In fact the kernel’s default definitions of \textasciitilde and \textasciicircum are literally those two. The named forms read more clearly in a manuscript, so prefer \textasciitilde{} and \textasciicircum{}.
For the backslash itself, use \textbackslash. Do not use \\ — that is not two backslashes but the line-break command, and it prints nothing. The interesting part is that the default text font has no backslash in it at all. The kernel declares that \textbackslash is to be taken from the math-symbol encoding, and sure enough, a one-page PDF whose only content is \textbackslash embeds CMSY10, the math symbol font. For the same reason the default \_ is not a character but a thin rule drawn by hand: a page containing only \_ embeds no font whatsoever. Add \usepackage[T1]{fontenc} and both switch to proper glyphs from the text font. While you are there: <, > and | are not reserved characters at all, yet in the default encoding they come out as ¡ ¿ — . fontenc fixes those too.
\usepackage[T1]{fontenc} % real glyphs for \, _, < > |
100\% \& \$5 cost \#1
A Windows path: C:\textbackslash Users\textbackslash doc
Standalone marks: \textasciitilde{} and \textasciicircum{}Setting accents
Early TeX could read nothing but 7-bit ASCII. To get é you had to instruct it to place an acute accent over an e, and those instructions are still here. The pattern is accent command plus letter: \'e is é, \"o is ö, \^e is ê, \~n is ñ, \c{c} is ç, \v{s} is š, \r{a} is å. One trap deserves mention: when accenting i or j the dot is in the way, so use the dotless \i and \j and write \'{\i}.
| Command | Example | Name |
|---|---|---|
\' | é | Acute |
\` | è | Grave |
\^ | ê | Circumflex |
\" | ö | Umlaut or diaeresis |
\~ | ñ | Tilde |
\= | ō | Macron |
\. | ż | Dot above |
\u | ğ | Breve |
\v | š | Caron or háček |
\H | ő | Double acute |
\c | ç | Cedilla |
\r | å | Ring above |
\d | ṣ | Dot below |
\b | o̲ | Bar below |
\t | o͡o | Tie joining two letters |
Some letters cannot be built from an accent at all. The German eszett \ss (ß), the Nordic \aa (å) and \o (ø), the Polish \l (ł) and the ligatures \ae (æ) and \oe (œ) are letters in their own right, so they have commands of their own. Capitals come from capitalising the spelling: \AA, \O, \L, \AE, \OE. All of these are standard LaTeX and need no extra package.
Typing non-ASCII directly in UTF-8
In current LaTeX you can simply type café, Grüße and naïve. Since the release of April 2018 — LaTeX News 28 carries the section “UTF-8: the new default input encoding” — UTF-8 is the kernel’s default input encoding, so \usepackage[utf8]{inputenc} is no longer needed (it does no harm, and old documents still compile). \usepackage[T1]{fontenc} is still worth adding, though: it switches the output side to an 8-bit font encoding, so accented words hyphenate correctly and text copied out of the PDF comes back intact. With XeLaTeX and LuaLaTeX the story is simpler still — select an OpenType font with fontspec and both input and output are Unicode from the start.
% pdfLaTeX: UTF-8 input is the default; T1 fixes output and hyphenation
\usepackage[T1]{fontenc}
café, Gr\"u\ss e, na\"{\i}ve, \AA ngstr\"om, \oe uvre, a\~no
% XeLaTeX / LuaLaTeX: Unicode all the way through
% \usepackage{fontspec}
% \setmainfont{TeX Gyre Pagella}When there are many specials: \verb and \url
Escaping a symbol-heavy fragment one character at a time is laborious, and the odds of missing one go up fast. That is what the verbatim mechanism is for. Inline, write \verb|...|, fencing the text with any character that does not occur inside it (here |); within the fence every reserved character loses its special meaning and the text is set in a typewriter face. For several lines, use the verbatim environment. One restriction: \verb cannot appear inside an argument — \section{... \verb|x| ...} gives ! LaTeX Error: \verb illegal in argument. For strings that tend to contain ~, #, % or _ — URLs above all — the best answer is \url{...} from the url or hyperref package: it handles the reserved characters inside automatically, sets them in a monospaced font, and breaks a long URL at sensible places.
\usepackage{hyperref} % provides \url as well
Use \verb|a_b^c & d%| to show specials literally.
\begin{verbatim}
foo_bar = 100% & #1 % every character printed as-is
\end{verbatim}
See \url{https://example.com/path?id=1#sec_2~ok}When pasted data breaks a table
In a real manuscript, special characters rarely arrive because you typed them. They arrive pasted — from a CSV file, a web page, an email, a PDF. Tables are where this hurts most. Because & separates columns, a single bare ampersand in a company name or a paper title throws the column count off, producing ! Misplaced alignment tab character &. or quietly swallowing the second half of the row. The quickest defence is to sort the incoming material into three kinds before pasting it: text to be read as prose, code to be shown as-is, and URLs to be processed as links. Once sorted, the escaping strategy chooses itself.
% before pasting into a table, search the pasted region for & % _ #
\begin{tabular}{ll}
Smith \& Wesson & company name \\
95\% & reported rate \\
\end{tabular}
% do not escape URLs by hand; hand them to \url
\url{https://example.com/report?id=95#table_1}In summary the decision has about three steps. One or two symbols inside prose: escape them as in the table. A block of code or terminal output: hand it to \verb or verbatim. A URL: give it to \url{}. Then, when the symptoms appear — a table shifted by one column, the second half of a row gone, a sudden ! Missing $ inserted. — search only the pasted region and sort each &, %, _ and # into “prose” or “LaTeX syntax”. That is almost always where the cause is sitting.