Special characters in LaTeX: percent, underscore, ampersand, backslash

Ten characters have a special meaning in LaTeX: #, $, %, &, _, {, }, ~, ^ and the backslash. Seven of them are printed with a backslash in front, for example \% and \_. The backslash, the tilde and the caret have commands of their own.

Seven characters with a backslash

\#, \$, \%, \&, \_, \{ and \} print the character itself.

50\% of \$20, item \#3, R\&D, file\_name and \{braces\}
Result
The compiled example

Open in the editor

Backslash, tilde and caret

These three need a command, because \\ is a line break and \~ and \^ put an accent on the next letter. \textbackslash prints a backslash, \textasciitilde a tilde and \textasciicircum a caret.

C:\textbackslash Users, \textasciitilde user and 2\textasciicircum 10
Result
The compiled example

Open in the editor

Less than, greater than and the vertical bar

In the default font encoding, <, > and | in normal text print an inverted exclamation mark, an inverted question mark and a dash. Use \textless, \textgreater and \textbar, or load \usepackage[T1]{fontenc}, after which the keys print the right characters. In math mode the three keys always work.

a \textless{} b \textgreater{} c \textbar{} d and $a < b > c$
Result
The compiled example

Open in the editor

Print code and paths unchanged

\verb prints everything between two equal delimiter characters as typed, in typewriter font. The delimiter can be any character that does not occur in the text, here |.

The file is \verb|C:\Users\name_1\notes#2.txt|.
Result
The compiled example

Open in the editor

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages