Section 207: The command codes

Before we can go any further, we need to define symbolic names for the internal code numbers that represent the various commands obeyed by . These codes are somewhat arbitrary, but not completely so. For example, the command codes for character types are fixed by the language, since a user says, e.g., ‘\catcode `\$ = 3’ make $ a math delimiter, and the command code MATH_SHIFT is equal to 3. Some other codes have been made adjacent so that case statements in the program need not consider cases that are widely spaced, or so that case statements can be replaced by if statements.

At any rate, here is the list, for future reference. First come the “catcode” commands, several of which share their numeric codes with ordinary commands when the catcode cannot emerge from ’s scanning routine.

constants.h
#define ESCAPE        0  // escape delimiter (called \ in The TeXbook)
#define RELAX         0  // do nothing (\relax)
#define LEFT_BRACE    1  // beginning of a group ({)
#define RIGHT_BRACE   2  // ending of a group (})
#define MATH_SHIFT    3  // mathematics shift character ($)
#define TAB_MARK      4  // alignment delimiter (&, \span)
#define CAR_RET       5  // end of line (CARRIAGE_RETURN, \cr, \crcr)
#define OUT_PARAM     5  // output a macro parameter
#define MAC_PARAM     6  // macro parameter symbol (#)
#define SUP_MARK      7  // superscript (^)
#define SUB_MARK      8  // subscript (_)
#define IGNORE        9  // characters to ignore (^^@)
#define ENDV          9  // end of <v_j> list in alignment template
#define SPACER        10 // characters equivalent to blank space ( )
#define LETTER        11 // characters regarded as letters (A..Z, a..z})
#define OTHER_CHAR    12 // none of the special character types
#define ACTIVE_CHAR   13 // characters that invoke macros (~)
#define PAR_END       13 // end of paragraph (\par)
#define MATCH         13 // match a macro parameter
#define COMMENT       14 // characters that introduce comments (%)
#define END_MATCH     14 // end of parameters to macro
#define STOP          14 // end of job (\end, \dump)
#define INVALID_CHAR  15 // characters that shouldn't appear (^^?)
#define DELIM_NUM     15 // specify delimiter numerically (\delimiter)
#define MAX_CHAR_CODE 15 // largest catcode for individual characters

Section 208

Next are the ordinary run-of-the-mill command codes. Codes that are MIN_INTERNAL or more represent internal quantities that might be expanded by ‘\the’.

constants.h
#define CHAR_NUM                 16 // character specified numerically (\char)
#define MATH_CHAR_NUM            17 // explicit math code (\mathchar)
#define MARK                     18 // mark definition (\mark)
#define XRAY                     19 // peek inside of TeX (\show, \showbox, etc.)
#define MAKE_BOX                 20 // make a box (\box, \copy, \hbox, etc.)
#define HMOVE                    21 // horizontal motion (\moveleft, \moveright)
#define VMOVE                    22 // vertical motion (\raise, \lower)
#define UN_HBOX                  23 // unglue a box (\unhbox, \unhcopy)
#define UN_VBOX                  24 // unglue a box (\unvbox, \unvcopy)
#define REMOVE_ITEM              25 // nullify last item (\unpenalty, \unkern, \unskip)
#define HSKIP                    26 // horizontal glue (\hskip, \hfil, etc.)
#define VSKIP                    27 // vertical glue (\vskip, \vfil, etc.)
#define MSKIP                    28 // math glue (\mskip)
#define KERN                     29 // fixed space (\kern)
#define MKERN                    30 // math kern (\mkern)
#define LEADER_SHIP              31 // use a box (\shipout, \leaders, etc.)
#define HALIGN                   32 // horizontal table alignment (\halign)
#define VALIGN                   33 // vertical table alignment (\valign)
#define NO_ALIGN                 34 // temporary escape from alignment (\noalign)
#define VRULE                    35 // vertical rule (\vrule)
#define HRULE                    36 // horizontal rule (\hrule)
#define INSERT                   37 // vlist inserted in box (\insert)
#define VADJUST                  38 // vlist inserted in enclosing paragraph (\vadjust)
#define IGNORE_SPACES            39 // gobble |spacer| tokens (\ignorespaces)
#define AFTER_ASSIGNMENT         40 // save till assignment is done (\afterassignment)
#define AFTER_GROUP              41 // save till group is done (\aftergroup)
#define BREAK_PENALTY            42 // additional badness (\penalty)
#define START_PAR                43 // begin paragraph (\indent, \noindent)
#define ITAL_CORR                44 // italic correction (\/)
#define ACCENT                   45 // attach accent in text (\accent)
#define MATH_ACCENT              46 // attach accent in math (\mathaccent)
#define DISCRETIONARY            47 // discretionary texts (\-, \discretionary)
#define EQ_NO                    48 // equation number (\eqno, \leqno)
#define LEFT_RIGHT               49 // variable delimiter (\left, \right)
#define MATH_COMP                50 // component of formula (\mathbin, etc.)
#define LIMIT_SWITCH             51 // diddle limit conventions (\displaylimits, etc.)
#define ABOVE                    52 // generalized fraction (\above, \atop, etc.)
#define MATH_STYLE               53 // style specification (\displaystyle, etc.)
#define MATH_CHOICE              54 // choice specification (\mathchoice)
#define NON_SCRIPT               55 // conditional math glue (\nonscript)
#define VCENTER                  56 // vertically center a vbox (\vcenter)
#define CASE_SHIFT               57 // force specific case (\lowercase, \uppercase)
#define MESSAGE                  58 // send to user (\message, \errmessage)
#define EXTENSION                59 // extensions to \TeX\ (\write, \special, etc.)
#define IN_STREAM                60 // files for reading (\openin, \closein)
#define BEGIN_GROUP              61 // begin local grouping (\begingroup)
#define END_GROUP                62 // end local grouping (\endgroup)
#define OMIT                     63 // omit alignment template (\omit)
#define EX_SPACE                 64 // explicit space (\ )
#define NO_BOUNDARY              65 // suppress boundary ligatures (\noboundary)
#define RADICAL                  66 // square root and similar signs (\radical)
#define END_CS_NAME              67 // end control sequence (\endcsname)
#define MIN_INTERNAL             68 // the smallest code that can follow \the
#define CHAR_GIVEN               68 // character code defined by \chardef
#define MATH_GIVEN               69 // math code defined by \mathchardef
#define LAST_ITEM                70 // most recent item (\lastpenalty, \lastkern, \lastskip)
#define MAX_NON_PREFIXED_COMMAND 70 // largest command code that can't be \global

Section 209

The next codes are special; they all relate to mode-independent assignment of values to ’s internal registers or tables. Codes that are MAX_INTERNAL or less represent internal quantities that might be expanded by ‘\the’.

constants.h
#define TOKS_REGISTER     71  // token list register (\toks)
#define ASSIGN_TOKS       72  // special token list (\output, \everypar, etc.)
#define ASSIGN_INT        73  // user-defined integer (\tolerance, \day, etc.)
#define ASSIGN_DIMEN      74  // user-defined length (\hsize, etc.)
#define ASSIGN_GLUE       75  // user-defined glue (\baselineskip, etc.)
#define ASSIGN_MU_GLUE    76  // user-defined muglue (\thinmuskip, etc.)
#define ASSIGN_FONT_DIMEN 77  // user-defined font dimension (\fontdimen)
#define ASSIGN_FONT_INT   78  // user-defined font integer (\hyphenchar, \skewchar)
#define SET_AUX           79  // specify state info (\spacefactor, \prevdepth)
#define SET_PREV_GRAF     80  // specify state info (\prevgraf)
#define SET_PAGE_DIMEN    81  // specify state info (\pagegoal, etc.)
#define SET_PAGE_INT      82  // specify state info (\deadcycles, \insertpenalties)
#define SET_BOX_DIMEN     83  // change dimension of box (\wd, \ht, \dp)
#define SET_SHAPE         84  // specify fancy paragraph shape (\parshape)
#define DEF_CODE          85  // define a character code (\catcode, etc.)
#define DEF_FAMILY        86  // declare math fonts (\textfont, etc.)
#define SET_FONT          87  // set current font (font identifiers)
#define DEF_FONT          88  // define a font file (\font)
#define REGISTER          89  // internal register (\count, \dimen, etc.)
#define MAX_INTERNAL      89  // the largest code that can follow \the
#define ADVANCE           90  // advance a register or parameter (\advance)
#define MULTIPLY          91  // multiply a register or parameter (\multiply)
#define DIVIDE            92  // divide a register or parameter (\divide)
#define PREFIX            93  // qualify a definition (\global, \long, \outer)
#define LET               94  // assign a command code (\let, \futurelet)
#define SHORTHAND_DEF     95  // code definition (\chardef, \countdef, etc.)
#define READ_TO_CS        96  // read into a control sequence (\read)
#define DEF               97  // macro definition (\def, \gdef, \xdef, \edef)
#define SET_BOX           98  // set a box (\setbox)
#define HYPH_DATA         99  // hyphenation data (\hyphenation, \patterns)
#define SET_INTERACTION   100 // define level of interaction (\batchmode, etc.)
#define MAX_COMMAND       100 // the largest command code seen at |big_switch|

Section 210

The remaining command codes are extra special, since they cannot get through ’s scanner to the main control routine. They have been given values higher than MAX_COMMAND so that their special nature is easily discernible. The “expandable” commands come first.

constants.h
#define UNDEFINED_CS    (MAX_COMMAND + 1)  // initial state of most |eq_type| fields
#define EXPAND_AFTER    (MAX_COMMAND + 2)  // special expansion (\expandafter)
#define NO_EXPAND       (MAX_COMMAND + 3)  // special nonexpansion (\noexpand)
#define INPUT           (MAX_COMMAND + 4)  // input a source file (\input, \endinput)
#define IF_TEST         (MAX_COMMAND + 5)  // conditional text (\if, \ifcase, etc.)
#define FI_OR_ELSE      (MAX_COMMAND + 6)  // delimiters for conditionals (\else, etc.)
#define CS_NAME         (MAX_COMMAND + 7)  // make a control sequence from tokens (\csname)
#define CONVERT         (MAX_COMMAND + 8)  // convert to text (\number, \string, etc.)
#define THE             (MAX_COMMAND + 9)  // expand an internal quantity (\the)
#define TOP_BOT_MARK    (MAX_COMMAND + 10) // inserted mark (\topmark, etc.)
#define CALL            (MAX_COMMAND + 11) // non-long, non-outer control sequence
#define LONG_CALL       (MAX_COMMAND + 12) // long, non-outer control sequence
#define OUTER_CALL      (MAX_COMMAND + 13) // non-long, outer control sequence
#define LONG_OUTER_CALL (MAX_COMMAND + 14) // long, outer control sequence
#define END_TEMPLATE    (MAX_COMMAND + 15) // end of an alignment template
#define DONT_EXPAND     (MAX_COMMAND + 16) // the following token was marked by \noexpand
#define GLUE_REF        (MAX_COMMAND + 17) // the equivalent points to a glue specification
#define SHAPE_REF       (MAX_COMMAND + 18) // the equivalent points to a parshape specification
#define BOX_REF         (MAX_COMMAND + 19) // the equivalent points to a box node, or is |null|
#define DATA            (MAX_COMMAND + 20) // the equivalent is simply a halfword number