Which symbols need to be escaped in ConTeXt?

Elaborating on @egreg's answer (sorry, too long for a comment): ConTeXt also has the \asciimode command. After that, only \, { and } have their typical category codes, all other special characters have catcode 12 (other). In that mode, to type in math, you need to elaborate as in \mathematics{a_2} (as dollar signs do not work any more) but it is really useful for some types of input file.

Special characters input list:

# is \#
$ is \textdollar
% is \percent
& is \&
\ is \textbackslash
^ is \textcircumflex
_ is \textunderscore
{ is \textbraceleft
| is \textbar
} is \textbraceright
~ is \textasciitilde

and low-level approaches like \char`| or \char`^ also work.


With the cont-en format the following characters have special category codes, so they can't be used for printing themselves:

# has catcode 6
$ has catcode 3
% has catcode 14
& has catcode 4
\ has catcode 0
^ has catcode 7
_ has catcode 8
{ has catcode 1
| has catcode 13
} has catcode 2
~ has catcode 13

The active | translates to \catcodecommand{124}, which is used for changing category code tables. For printing | in text mode one can use \|. In math mode | is not active.


TeX and friends are generally set up to only print out characters that are classified in the categories of letter -- all uppercase and lowercase alphabetic characters -- and other -- all digits and punctuation characters, but with certain important exceptions noted in the next paragraph.

Not all punctuation characters, however, fall into the "other" category. The exceptions are assigned to special category codes and serve as shortcuts for starting and ending frequently-occurring tasks. There are ten special characters common to all TeX engines I'm familiar with:

   Name        Cat code   Purpose
\  backslash   0          Start of a control sequence
{  left-brace  1          Start of a TeX "group"
}  right-brace 2          End of a "TeX" group
$  dollar      3          Opening and closing delimiter for math formulas
&  ampersand   4          Column separator in tables (tabulars and arrays)
#  hash        6          Parameter(s) of macros
^  circumflex  7          Precede superscript expressions in math mode
_  underscore  8          Precede subscript expressions in math mode
~  tilde       13         Tie (unbreakable space); an example of an "active" character
%  percent     14         Start of a comment

To display most of these special characters, all one has to do is to prefix a backslash (\) to them; e.g., \$ and \% will print out $ and %. However, in LaTeX this method won't work for the \, ^, and ~ characters; for these, one should type \textbackslash, \textasciicircum, and \textasciitilde. (The control words \\, \^, and \~ do exist in LaTeX, of course, but they are not set up to print out the associated "special" character. Instead, they serve to denote a line break in a tabular or array environment (\\), to place a circumflex particle above the next character (\^), and to place a tilde particle above the following character (\~).

A superb reference on the topic of TeX category codes is Chapter 2 of Victor Eijkhout's book TeX by Topic.

Addendum: In ConTeXt, the | "punctuation" character is also an "active" character, i.e., its category code is 13 rather than 12 ("other"). As @TacoHoekwater notes in his answer, to print out the "pipe" character in ConTeXt you have to type something like \textbar. Incidentally, the \textbar macro works in LaTeX as well.