Special characters in LaTeX
Ten characters do jobs in LaTeX instead of printing: the hash, dollar, percent, ampersand, tilde, underscore, caret, backslash and the two braces. Put a backslash before seven of them, \# \$ \% \& \_ \{ \}, to print them; the other three have commands of their own.
LaTeX command
\% \$ \& \# \_ \{ \}Not the symbol you meant? Draw it to find the command →
Typing up handwritten notes? Convert a whole page of handwriting to LaTeX →
% starts a comment, so everything after it on the line is ignored: that is why 50% makes the rest of a sentence vanish. Write 50\%. A % at the very end of a line also swallows the line break, which macro writers use on purpose to avoid a stray space.
The dollar sign switches maths on and off, & separates table and alignment columns, # numbers macro arguments, _ and ^ make subscripts and superscripts, and { } group. Escaped with a backslash they print as themselves: \$, \&, \#, \_, \{, \}. These work in text and in maths alike.
Three need words instead. ~ is a space that cannot break, so print a tilde with \textasciitilde. ^ is printed with \textasciicircum. And \\ is a line break, not a backslash, so print a backslash with \textbackslash in text, or \backslash in maths.
Copy the escaped characters
The seven a backslash fixes, then the three with commands of their own. All of them are built into LaTeX.
\# \$ \% \& \_ \{ \}\textasciitilde \textasciicircum \textbackslashSpecial characters in web addresses
\url from the url or hyperref package prints an address as typed, _, ~, % and # included, so there is nothing to escape. Inside another command's argument, such as a footnote, % and # still need their backslash.
\url{https://example.com/my_file?x=1#top}Other forms
\textbackslasha backslash in text\textasciitildea tilde in text\textasciicircuma caret in text\url{https://example.com/a_b}a web address, url packageExamples
$50\%$a percent sign
$\$5.99$a dollar sign
$\{1, 2, 3\}$braces printed as braces
$\#A = 3$a hash sign, here for the size of a set
$\text{file\_name}$an underscore in text
$A \backslash B$a backslash in maths
Tips and common mistakes
- A bare % starts a comment and hides the rest of the line; write \%.
- \\ is a line break, not a backslash; use
\textbackslashin text. - ~ prints a non-breaking space; use
\textasciitildefor the character. - Inside
\url, type the address as it is; only inside another command's argument do % and # need escaping. - Set braces in maths need escaping too: \{1, 2\}, since plain { } only group.
Working from handwritten notes?
LatexNotes turns a photo or PDF of handwritten mathematics into LaTeX, graphs and all. It is built with real pdflatex before you see it, and the .tex file is yours to edit or take to Overleaf. Free to try, no sign-up.
See how handwriting to LaTeX works, step by step, or go from GoodNotes to LaTeX if you write on an iPad (Notability works the same way).
Convert your maths to LaTeX →FAQ
How do I type a percent sign in LaTeX?
Write \%. A bare % starts a comment, so the rest of the line disappears.
How do I type an underscore in LaTeX?
Write \_ in text or maths. A bare _ makes a subscript and is an error outside maths.
How do I type a backslash in LaTeX?
Write \textbackslash in text or \backslash in maths. \\ is a line break.
Which characters need escaping in LaTeX?
The hash, dollar, percent, ampersand, underscore and braces take a backslash: \# \$ \% \& \_ \{ \}. The tilde, caret and backslash itself take \textasciitilde, \textasciicircum and \textbackslash.