Ten characters are invisible commands in LaTeX. The two that bite hardest are %, which deletes the rest of the line without a word, and &, which means "column separator" inside a table and breaks the build anywhere else. Escaping each is one backslash; understanding why it needs escaping is what makes the error messages readable. Underscores and carets are really Sub & Sup in disguise.
Which one to use
\%\$\&\_\#\textbackslashThe commands
50\%
\$5
A \& B
a_{max}
\#1
\{ x \}
\tilde{a}
\hat{x}
\setminus for a set difference instead. \backslash
a\quad b \qquad c
Worked examples
A percentage inside a formula
\frac{65\%}{100\%} = 0.65
Without the escapes the line ends at the first percent sign and the fraction never closes.
Currency in maths
\$1{,}000 - \$250 = \$750
The comma braces keep the thousands separator at normal baseline rather than as a decimal list separator.
Set-builder in a web page
\{ x : x > 0 \}
Braces escaped, colon rather than HTML entity for the inequality, because entities are not LaTeX.
File-like names
x_{\text{input\_file}}
Inside \text{} an underscore still needs escaping; there is no quoting mode that lifts the rule.
Common mistakes
- Pasting
&or<into LaTeX source. Entities belong to HTML; LaTeX sees an ampersand followed by letters and treats it as a table cell break. - Doubling up escapes while moving text between tools:
\\fracin a file that wanted\frac. This is the most common corruption in pasted converter output. - Wrapping maths in
$...$and forgetting that a second unescaped$anywhere later in the paragraph restarts maths mode from there. - Assuming braces are harmless because they are invisible. An unmatched
}is a hard error, and a missing pair silently changes what a subscript covers.
Questions about this notation
How do I type a percent sign in LaTeX?
How do I escape an underscore?
\text{} and escape inside it.Why does my ampersand break the build?
How do I type a backslash, a hash sign or a tilde in running text?
\textbackslash{}, a hash is \# and a visible tilde is \textasciitilde{} — not \~, which is an accent that needs a letter after it. Literal braces are \{ and \}. The empty group on the \text... forms stops them eating the space that follows, which is why \textasciitilde x and \textasciitilde{} x differ.Keep reading
Three ways into the same idea: the notation itself, the lesson that teaches it, and an article that applies it.