Questions tagged [catcodes]

{catcodes} is about "category codes" — an integer number from 0–15 associated to each of the 256 character codes. The category codes indicate the role of a character.

is about "category codes" — an integer number from 0–15 associated to each of the 256 character codes. The category codes indicate the role of a character.

The following is a list of the sixteen category codes and the Plain TeX settings:

  • 0 = Escape character; this signals the start of a control sequence. IniTeX makes the backslash \ (code 92) an escape character.

  • 1 = Beginning of group; such a character causes TeX to enter a new level of grouping. The plain format makes the open brace { a beginning-of-group character.

  • 2 = End of group; TeX closes the current level of grouping. Plain TeX has the closing brace }as end-of-group character.

  • 3 = Math shift; this is the opening and closing delimiter for math formulas. Plain TeX uses the dollar sign $ for this.

  • 4 = Alignment tab; the column (row) separator in tables made with \halign (\valign). In Plain TeX this is the ampersand &.

  • 5 = End of line; a character that TeX considers to signal the end of an input line. IniTeX assigns this code to the return, that is, code 13. Not coincidentally, 13 is also the value that IniTeX assigns to the \endlinechar parameter.

  • 6 = Parameter character; this indicates parameters for macros. In plain TeX this is the hash sign #.

  • 7 = Superscript; this precedes superscript expressions in math mode. It is also used to denote character codes that cannot be entered in an input file; see below. In Plain TeX this is the circumflex ^.

  • 8 = Subscript; this precedes subscript expressions in math mode. In plain TeX the underscore _ is used for this.

  • 9 = Ignored; characters of this category are removed from the input, and have therefore no influence on further TeX processing. In Plain TeX this is the null character, that is, code 0.

  • 10 = Space; space characters receive special treatment. IniTeX assigns this category to the ASCII space character, code 32.

  • 11 = Letter; in IniTeX only the characters a..z, A..Z are in this category. Often, macro packages make some ‘secret’ character (for instance @) into a letter.

  • 12 = Other; IniTeX puts everything that is not in the other categories into this category. Thus it includes, for instance, digits and punctuation.

  • 13 = Active; active characters function as a TeX command, without being preceded by an escape character. In Plain TeX this is only the tie character ~, which is defined to produce an unbreakable space.

  • 14 = Comment character; from a comment character onwards, TeX considers the rest of an input line to be comment and ignores it. In IniTeX the percent sign % is made a comment character.

  • 15 = Invalid character; this category is for characters that should not appear in the input. IniTeX assigns the ASCII delete character, code 127, to this category.

The user can change the mapping of character codes to category codes with the \catcode command.

348 questions
13
votes
1 answer

Catcodes of unicode characters with \usepackage[utf8]{inputenc}

I don't understand why this is generating an error message... \documentclass{article} \usepackage[utf8]{inputenc} \begin{document} \catcode`ẟ=\active \end{document} As the inputenc suggests, I'm using pdflatex.* Shouldn't the inputenc import cause…
Mohan
  • 15,906
12
votes
1 answer

Is there some reason I can't change catcodes inside a command?

I have a very simple question. When I do this: \catcode`\@=0 \catcode`\\=11 @mycommand{a} @catcode`@\=0 \catcode`\@=11 It works perfectly and calls \mycommand correctly. However, when I try to define \mycommand with similar…
Joseph R.
  • 876
8
votes
1 answer

catcode as used in defining Hypergeometric Function

This is perhaps not a very intelligent question, as I am not (of great intelligence nor) well versed in raw tex, even more so \catcode but in the code given in a previous answer there is a use of…
6
votes
3 answers

Setting catcodes in a group

Can someone explain to my why \foo and \bar are not the same (in the \ifx sense) in this example: \documentclass{article} \begingroup \catcode`|=3\relax \gdef\abc{|} \endgroup \makeatletter \newcommand\foobar{ \begingroup …
StrongBad
  • 20,495
6
votes
1 answer

Scantokens and Let

The package inputenc makes it possible, for example, to write ° to print a degree symbol. Simplifying a bit, it obtains that by making it an active character (catcode 13) and defining the corresponding macro. If its category is changed to other…
6
votes
2 answers

Viewing a character's catcode, and listing all characters with a given catcode

How can I view the catcode of a character given by its ASCII number? Is there a way to list all the characters (represented by their ASCII numbers) that are associated with a given catcode? For instance, how to list all the end-of-line characters,…
Evan Aad
  • 11,066
5
votes
2 answers

Catcode change doesn't take effect

Why does the following TeX manuscript result in an error upon compilation with TeX Version 3.14159265 (TeX Live 2017)? \catcode`}=12}\bye The error is: ! Too many }'s. } l.1 \catcode`}=12} \bye What I expected to…
Evan Aad
  • 11,066
4
votes
2 answers

Understanding this example of modifying category code

There was a question about automatically adding space after the periods and commas. An answer to it included modifying category code. It is shown…
youthdoo
  • 861
4
votes
3 answers

About catcodes and active characters

I'm reading about catcodes and I want to play a bit with them. However, there's a point I don't really understand. When I want to define an active character, e.g., square brackets ([ and ]) I do the following: \catcode`[ = \active \catcode`] =…
user193767
4
votes
1 answer

Setting the backslash's catcode

For fun, I want to change the backslash's catcode from 0 to 12. However, I can't seem to make it work. Here's my current MWE, which gives an error "improper alphabetic constant": \catcode`\textbackslash=12 I know that \textbackslash is not the…
Someone
  • 539
4
votes
1 answer

What will happen if I change the category code of digits to 11? (i.e. \makedigitsletter)

In this post, @Heiko Oberdiek said BUT each number TeX expects have to be catcode 12 (the problems)! Eg. \hspace{1em} What does he meant by "each number"? In addition to counters/dimensions/glues, which of the following will…
Symbol 1
  • 36,855
4
votes
1 answer

Is there any way to have a catcode set only inside a macro?

I was wondering if it's at all possible to change a catcode for use only inside a macro definition. In this case, I need to have one macro defined as \example#1#2, and another defined as \example^#1#2. The code below is working if \test{\example^25}…
4
votes
3 answers

How can I typeset a bibkey with &?

I would like to typeset a catalog of all my BibTeX entries. I have been using & in many bibkey's such as Author&Editor:2000. But I cannot \catcode38=12 globally. My question is: how can I typeset such a bibkey both in a section heading, and in the…
n.r.
  • 4,942
3
votes
2 answers

How to check whether some \catcode is \active?

I'm going to change a catcode to active and then implement my own formatting of small verbs: \if-not-active \catcode`|=\active \def|#1|{\foo{#1}} \fi I want to make this non-intrusive and check first, whether it's already active. If it is, make…
yegor256
  • 12,021
3
votes
1 answer

How to redefine symbols inside my custom environment?

I'm trying to create my own foo environment, which would be used like this: \documentclass{article} \begin{document} \begin{foo} a -> b [ c => d ] \end{foo} \end{document} I'm expecting it to render as: \begin{equation} \begin{split} & a \mapsto…
yegor256
  • 12,021
1
2