Escaping Special Characters in LaTeX

Escaping Special Characters in LaTeX

LaTeX uses several characters for special commands and environments. If you want to include these characters literally in your document, you need to "escape" them. Here's a quick guide on how to handle common special characters.

The Percent Sign (%)

The percent sign is used for comments in LaTeX. To display it, precede it with a backslash:

This is 100\% complete.

The Ampersand (&)

The ampersand is used for alignment in environments like align or tabular. To display it:

AT\&T is a company.

The Hash/Number Sign (#)

The hash sign is used in macro definitions. To display it:

The item number is \#1.

The Underscore (_) and Caret (^)

These are used for subscripts and superscripts, respectively. To display them literally:

Variable\_name and Power\textasciicircum{}2.

The Tilde (~)

The tilde creates a non-breaking space. To display it:

About the book: M\textasciitilde{}ocha.

The Dollar Sign ($)

The dollar sign is used to enter and exit math mode. To display it:

The price is \$10.

The Backslash (\)

The backslash is the escape character itself. To display a backslash, you need to use another backslash, usually with \textbackslash{} or \verb|\label{sec:intro}| for code snippets:

To write a new line, use \\ or \textbackslash{}.

Curly Braces ({ and })

Curly braces are used for grouping. To display them:

My favorite characters are \{ and \}.

Common Escapes Summary

Character LaTeX Command
% \%
& \&
# \#
_ \_
^ \^
~ \~{} (or \textasciitilde{})
$ \$
\ \textbackslash{}
{ \{
} \}

Comments

Popular Posts