# Which symbols need to be escaped in ConTeXt?

When writing "\$" or "%" in a document, one must used `\\$` and `\%` so that they will be interpreted as symbols which should be displayed along with the text.

• What other symbols need to be escaped in ConTeXt? Where can I obtain a complete list?

I have also observed that documents containing "|" cannot be compiled, but `\|" does not help. Why does this prevent compilation and how can this be displayed as text?

-

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.

-
I think I read somewhere that `%%` still starts a comment in asciimode, and to get two consecutive `%` one needs to do `%{}%`. Is that the case? –  Bruno Le Floch Mar 22 '12 at 17:14
Minor additions: You can use `\startasciimode ... \stopasciimode` if you don't want ascii mode to be active for the whole document. `\mathematics{...}` may be abbreviated to `\math{...}` or `\m{...}`. –  Aditya Mar 23 '12 at 2:50

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 seems to be used for changing category code tables. For printing `|` one can use `\char`|`, but surely there's a better ConTeXt way.

-

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.

-
`pdflatex`, `xelatex`, `lualatex` are not new format, they all are LaTeX with different engines, ConTeXt, on the other hand, is completely different format; they are not equal and listing them together is just confusing. –  Khaled Hosny Mar 22 '12 at 14:48
@KhaledHosny - thanks for pointing out that the current listing of these terms is confusing. I've actually decided to shorten my answer quite a bit, and that passage is now gone. –  Mico Mar 22 '12 at 15:40