# Why can't caret and tilde be escaped with backslash alone?

I can escape some special characters with a backslash.

\documentclass{article}
\begin{document}
\# \$\% \& \_ \{ \} \end{document}  But why can't I escape ^ and ~ with a backslash alone? For example, the code below does not work. \documentclass{article} \begin{document} \^ \end{document}  It causes the following error with texlive. $ pdflatex foo.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2015/dev/Debian) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
(./foo.tex
LaTeX2e <2014/05/01>
Babel <3.9l> and hyphenation patterns for 2 languages loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo)) (./foo.aux)
! Missing \endcsname inserted.
\global
l.4 \end
{document}
?
! Emergency stop.
\global
l.4 \end
{document}
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on foo.log.


In fact, I have to first escape with them a backslash and then add {} as a suffix to them to make it work.

\documentclass{article}
\begin{document}
\^{}
\~{}
\end{document}


I understand that {}, i.e. the empty parameter list, forces TeX to consider it as the end of a command and beginning of text again, but I want to understand why {} is necessary.

Two questions:

1. Why can't these characters be escaped with \ alone?
2. Is there any difference between \^{} and \^\? They seem to give the same output but I want to know if there is any difference between them that might product different results under any circumstances?
• Well because \^ is used to get the circumflex accent, e.g. \^e or \^{e} for ê and, again, \~ is for the tilde diacritic, as in \~{n} for ñ. In any case \^{} will give you the pure accent, it's like using a dead key on an old typewriter and then hitting the space. It may be better to use other ways to produce the ^ and the ~ – Au101 Jun 6 '16 at 1:46
• Notice also that there is \sim and there is \wedge. – Michael Hardy Jun 6 '16 at 4:04
• You can do \string^ and \string~. – Manuel Jun 6 '16 at 7:02

Although we commonly say that \ is the escape character, it's really the character that TeX uses to introduce a control sequence. There are two types of control sequences. Control words consist of \ plus a string of letters. Control symbols consist of \ plus a single non-letter.

But in neither case is \ acting as an escape per se. Each of the characters you think of as being "escaped" are really control symbols which all have actual definitions. Some simply expand to their corresponding character, but others do not. Here are their actual definitions:

*\show\#
> \#=\char"23.

*\show\$> \$=\char"24.

*\show\%
> \%=\char"25.

*\show\&
> \&=\char"26.

*\show\{
> \{=macro:
->\delimiter "4266308 .

*\show\}
> \}=macro:
->\delimiter "5267309 .

*\show\^
> \^=macro:
#1->{\accent 94 #1}.

*\show\'
> \'=macro:
#1->{\accent 19 #1}.

*\show\~
> \~=macro:
#1->{\accent "7E #1}.


Notice that in the case of \^, \~, and \' the macro definitions take an argument. So they will take their next character as that argument. If you don't want that to happen, you need to explicitly stop it with the {}.

To answer your second question, \^{} is not identical to \^\ since the latter will insert a space but the former will not. So for example:

\^\ foo \^{}foo


will yield the following output:

Alan has explained why \^ takes an argument but note also that latex has \textbackslash, \textasciicircum and \textasciitilde to generate \ ^ ~ In the case of the original OT1 encoding \textasciicircum and \textasciitilde are in fact the same as \^{} and \~{} that is put an accent over an empty base, and \backslash takes a \ from the math symbol font as the OT1 encoding does not contain these characters.

However if you use T1 (or any normal encoding that does have \, ^ and ~ characters) then \textasciicircum and \textasciitilde will use the characters from the font in those positions, which are normally larger and lower than the accents, and \backslash will use a \ from the current font.

• ascii with two i's? – Torbjørn T. Jun 6 '16 at 6:55
• @TorbjørnT. you have edit rights:-) thanks, I'll fix – David Carlisle Jun 6 '16 at 7:03