\def\testeq#1#2{\def\tmp{#2}\ifx#1\tmp\else \toks0={#1wantd: ->#2.}
\typeout{\the\toks0}\show #1\uerror\fi}
\def\xtesteq#1#2{\xdef\tmp{#2}\ifx#1\tmp\else \toks0={#1wantd: ->}
\typeout{\the\toks0 #2.}\show #1\uerror\fi}
This can be used as
\def\foo{something} \testeq\foo{Something else}
and will produce no XML, but an error and two lines of message, like
\foo wantd: ->Something else.
\foo=macro: ->something.
Error signaled at line 352:
Undefined command \uerror.
Note the following points. Both ''\typeout'' and ''\show'' print the value on the tty as well as the transcript file. The token list of ''\typeout'' is fully expanded, and for this reason, we put in a token list the quantity ''#1wantd: ->#2''. and inhibit expansion via ''\the''.
-----
Unless stated otherwise, a category code (in short a //catcode//) is an integer between **0** and **15**. It is a property of input characters, used by the scanner to convert the input stream into a sequence of tokens. The character with ASCII code 37 is the character ''%'', and is normally of category 14, thus behaves like a start-of-comment. You can insert such a character in the XML output via the sequence ''\char37'' (However ''\char60'' produces
{\def\foo{\gdef\bar{OK}} \catcode`x=0 xfoo}
\testeq\bar{OK}
{\def\foo{\gdef\bar{notOK}} \catcode`x=0xfoo}
\testeq\bar{OK}
The next example shows that the token after a control sequence like ''\foo'' can be of catcode letter (because when the character is read again, its catcode is analysed again).
{\def\bar#1{\egroup\show#1}
\def\foo{\bgroup\catcode32=11\catcode`\%=11 \bar}\foo \foo%\foo=\foo$\foo#}
In the Tralics output below, `the letter' means a character of category 11, `the character' a character of category 12.
the letter .
the letter %.
the character =.
math shift character $.
macro parameter character #.
===== Catcode 1 =====
Initially, the only character of catcode 1 is the open brace. See below.
===== Catcode 2 =====
Initially, the only character of catcode 2 is the closing brace.
The following example shows that you can use other characters. In Tralics, characters of catcode 1 and 2 serve two purposes: for grouping, so that modifications are local to a group, and for delimiting arguments.
{\catcode`A1\catcode`B2
\def\fooA2B\testeq\fooA2B
\def\barA\bgroup\def\fooA3B\egroupB\bar% \bar modifies \foo locally
\testeq\foo{2}}
Note the following trick: ''\uppercase \relax\bgroup}''. After ''\uppercase'' and commands like that, you can have an arbitrary sequence of spaces and ''\relax'' commands. The argument is delimited on the left by an implicit left brace, on the right by an explicit right brace.
===== Catcode 3 =====
Initially, the only character with catcode 3 is the dollar sign. It is used to enter and exit math and display math mode. A construct like ''{\catcode `x=3 \catcode`y=3 xy \sinxy}'' is the same as ''\[\sin\]''.
===== Catcode 4 =====
The only character with catcode 4 is the alignment tab character ''&''. (see description of arrays).
===== Catcode 5 =====
The only character with catcode 5 is the end-of-line character (carriage return, ASCII code 13). When
{\catcode`A6 \def\fooA1A2{\xdef\bar{A2A1}}\foo23
\testeq\bar{32}}
\def\Ma#1{\def\Mb ##1{\xdef\xbar{#1##1}}}\Ma a\Mb b
\testeq\xbar{ab}
\def\foo{###AA#AA}\def\fooB{##AA##AA} \def\fooC{####AAAA}
\ifx\foo\fooB\else\bad\fi \ifx\foo\fooC\bad\fi}
{1^^{^^ab2^^5e^ab3^^5e^5e^ab4\def\Abc{ok}\def\bAc{OK}\^^41bc\b^^41c}
{\catcode `\é=7 ééab $xé2$ %next line should produce M
éé
$1^è=^^^AééT$} %line contains hat, hat, control-A
\def\msg{A message.^^J}
This is the XML translation
1;« 2« 3« 4okOK
«
M
Note: The line that contains the two ''é'' characters translates as capital ''M'', because the last character on the line is the newline character, control-M (even though on Unix, you would expect control-J). The ''\msg'' command contains as last token a newline character (control-J of catcode 12), and not an end-of-line character of catcode 5. The character control-T, represented by '''' seems to be illegal in XML. Without it, the preview is some chars.
If you say ''^^^^ABCD'', the result is a character whose value is defined by the value ABCD (each letter must be a digit, or a lower case letter between A and F). Such a construct is equivalent to ''\char &ABCD'', but it is one token, and spaces are not ignored after it. (You can also use five hats, see the documentation on characters). Example
\def\foo#1#2#3{#1=#2=#3=}
\foo^^^^0153^^^^0152^^^^0178
^^^^017b^^8?
œ=Œ=Ÿ=
Żx?
===== Catcode 8 =====
The only character with catcode 8 is the underscore character. It is used for subscripts in math mode. See the ''\sp'' command for an example of use.
Outside math mode, you will get an error. For instance, if you say
{\catcode`x7 \catcode`y=8 a^b_c xy\sp\sb}
then Tralics will complain (but not in the same fashion as TeX).
Error signaled at line 377:
Missing dollar not inserted, token ignored: {Character ^ of catcode 7}.
Error signaled at line 377:
Missing dollar not inserted, token ignored: {Character _ of catcode 8}.
Error signaled at line 377:
Missing dollar not inserted, token ignored: {Character x of catcode 7}.
Error signaled at line 377:
Missing dollar not inserted, token ignored: {Character y of catcode 8}.
Error signaled at line 377:
Missing dollar not inserted, token ignored: \sp.
Error signaled at line 377:
Missing dollar not inserted, token ignored: \sb.
===== Catcode 9 =====
Characters of code 9 are ignored. Initially, no character has this category code.
===== Catcode 10 =====
A character of catcode 10 acts like a space. If TeX sees a character of catcode 10, the action depends on the current state. If the state is **N** or **S**, the character is ignored. Otherwise, TeX is in state **M** and changes to state **S**, and the result is a space token (character 32, category 10). Space, tabulation are of catcode 10.
Spaces are in general ignored at start of line, because TeX is in state **M**. In verbatim mode, the catcode of the space is changed, and thus spaces remain.
===== Catcode 11 =====
Characters of catcode letter can be used to make multiletter control sequences (without using ''\csname''). Only ASCII letter (between ''a'' and ''z'', or between ''A'' and ''Z'') are by default of catcode 11.
===== Catcode 12 =====
Characters of catcode 12 cannot be used to make multiletter control sequences.
All characters not listed elsewhere are of catcode 12 (especially, all 8-bit characters).
===== Catcode 13 =====
Characters of category 13 are active. They can be used only if a definition is associated. In Tralics only the tilde character is of 13, but the three characters ''_#&'' have a definition (the translation is the character). Note that, in PlainTeX, the tilde character expands to ''\penalty \@M \ '' (there is a space at the end of the command) and in LaTeX to ''\nobreakspace{}'', which is the same with a ''\leavevmode'' in front, in Tralics, the expansion is simply ''\nobreakspace''.
===== Catcode 14 =====
Characters of catcode 14 act like an start-of-comment character. The only character with catcode 14 is the percent character.
===== Catcode 15 =====
Characters of catcode 15 are invalid. There is no invalid character in Tralics.
===== Catcode 16 =====
There is no character of catcode 16 in TeX . In Tralics, this code is reserved for verbatim-like characters, defined by ''\DefineShortVerb''. These characters act is if they were preceded by ''\verb''. Note that the star character is not exceptional. You can use ''\fvset'', if you want to change the translation of a space.
Example:
\DefineShortVerb{\|}
Test of |\DefineShortVerb| and |\UndefineShortVerb|.
\DefineShortVerb{\+}
test 1 |toto| +x+ |+x-| +|t|+
\UndefineShortVerb{\+}
test 2 |toto| +x+ |+x-| +|t|+
espace: |+ +|\fvset{showspaces=true}|+ +|\fvset{showspaces=false}|+ +|.
\DefineShortVerb{\*}
Verbatimfoo: *+ foo +*\verb+*foo*+\verb*+foo*+
Verbatimfoo: \verb|+ foo +*foo*foo*|.
The XML output is the following
Test of \DefineShortVerb and \UndefineShortVerb.
test 1 toto x +x-
|t|
test 2 toto +x+ +x- +t+
espace: + ++␣++ +.
Verbatimfoo: + foo +*foo*foo*
Verbatimfoo: + foo +*foo*foo*.
We can continue the example as follows. We show how to use ''\SaveVerb'' and ''\UseVerb''.
\SaveVerb{FE}|}|\def\FE{\UseVerb{FE}}
\DefineShortVerb{\+}
\SaveVerb{VE}+|+\def\VE{\UseVerb{VE}}
\SaveVerb{DU}|$_|\def\DU{\UseVerb{DU}} %$
\UndefineShortVerb{\+}
\UndefineShortVerb{\|}
\UndefineShortVerb{\*}
Test \FE,\VE, \DU.
Test },|, $_.
-----
//Source:// [[https://www-sop.inria.fr/marelle/tralics/doc-symbols.html]]
{{htmlmetatags>metatag-keywords=(commandes de LaTeX,liste des catcodes,codes de catégorie,catégories de caractères)
metatag-og:title=(Quels sont les différents catcodes ?)
metatag-og:site_name=(FAQ LaTeX francophone)
}}