LaTeX has ten characters you cannot just type and expect to see: # $ % & _ { } ~ ^ \. Each one is reserved for a special job — starting a comment, switching to math, beginning a command, and so on. This page covers what each does, and how to print the character itself when you actually want it.
The ten reserved characters
A reserved character is one that LaTeX uses as part of its syntax, so typing it in your text triggers a behavior instead of printing. Type % and the rest of that line vanishes as a comment; type $ and you switch into math mode. To get such a character to appear as itself on the page, you have to do a little extra.
Here is what each one does. # stands for an argument in a macro definition; $ begins and ends math mode; % starts a comment (the rest of the line is ignored); & separates the columns (cells) of a table or alignment. _ and ^ introduce a subscript and a superscript in math; { and } delimit an argument or a group. ~ produces a non-breaking interword space, and \ (backslash) begins every command.
| Character | Its special job |
|---|---|
# | Argument in a macro definition (#1, #2, …) |
$ | Begins and ends math mode |
% | Starts a comment (rest of the line ignored) |
& | Column (cell) separator in tables and alignments |
_ | Subscript in math mode |
^ | Superscript in math mode |
{ | Opens an argument or group |
} | Closes an argument or group |
~ | Non-breaking interword space |
\ | Begins a command |
Printing the character itself
Seven of the ten are easy: just put a single backslash in front. That gives \#, \$, \%, \&, \_, \{, \}. Typing \$1.23, for example, prints $1.23. The backslash signals “the next character is itself, not the start of a command.”
The remaining three are trickier. Print ~ with \textasciitilde (or \~{}), and ^ with \textasciicircum (or \^{}). Written alone, \~ and \^ are *accent* commands and would place a tilde or hat over the next letter; adding an empty {} gives the accent nothing to sit on, leaving the bare symbol.
Finally, the backslash itself: print it with \textbackslash. **Do not use \\** — that is not two backslashes but the line-break (new-line) command. This is an easy and common trap.
| You type | You get | Notes |
|---|---|---|
\# | # | A single backslash in front |
\$ | $ | Same |
\% | % | Same |
\& | & | Same |
\_ | _ | Same |
\{ | { | Same |
\} | } | Same |
\textasciitilde | ~ | \~{} also works; bare \~ is an accent |
\textasciicircum | ^ | \^{} also works; bare \^ is an accent |
\textbackslash | \ | Not \\, which is a line break |
The commands \textbackslash, \textasciitilde, and \textasciicircum are part of the current LaTeX kernel and need no extra package (historically they came from textcomp). Note that some text fonts lack a standalone tilde or caret glyph in the body face; in those fonts these text-symbol commands are the reliable way to get the mark.
A worked example
Let us print a sentence packed with reserved characters, such as 100% & $5 cost #1. Each of %, &, $, # is escaped with a leading backslash.
100\% \& \$5 cost \#1
% backslash, tilde and caret need their own commands:
A path: C:\textbackslash Users \\
Math symbols out of math: \textasciitilde{} and \textasciicircum{}The first line sets as 100% & $5 cost #1. Below it, a Windows-style path uses a backslash (\textbackslash), and a standalone tilde and caret use \textasciitilde{} and \textasciicircum{} (the \\ at the end of the line is the command that breaks the output line — it does not print a backslash).
When you have many specials, or a URL
Escaping a dense snippet of code or symbols one character at a time is tedious. For that, the verbatim mechanism helps. Inline, write \verb|...|, fencing the text with any character that does not appear inside it (here |); its contents are set as-is in a typewriter font, with all special meanings switched off. For several lines, use the verbatim environment.
Use \verb|a_b^c & d%| to show specials literally.
\begin{verbatim}
foo_bar = 100% & #1 % all printed as-is
\end{verbatim}For strings that tend to contain ~, #, %, or _ — URLs above all — reach for \url{...} from the url (or hyperref) package. It handles the reserved characters inside automatically, sets them in a monospaced font, and breaks the line sensibly, so no manual escaping is needed.
\usepackage{hyperref}
% ...
See \url{https://example.com/path?id=1#sec_2~ok}In short: escape one-off symbols as in the table, hand dense snippets to \verb/verbatim, and let \url{} take URLs. The wider logic of the syntax is covered in “Syntax rules,” and the many text symbols you can use in the body live on the “Text symbols” page.