% This is part of the Tcode kernel. Only intended to by input by it.

%%%%%%%%%%*******   Setting the catcodes on entry of each of the macros   *******%%%%%%%%%%

%Macros for producing common escape sequences in strings. We want the user to typeset the string as if it were
%code: "\tThe title is: \"Hamlet\"\n". So that \t should produce \t, etc.
%The ones with \ignorespaces are for macros that rescan its argument and set <space> active. The only one is \ncode (and its variant \nscode)
\edef\Nc@dq{\string\"} \edef\Nc@sq{\string\`} \edef\Nc@nl{\string\n} \edef\Nc@tab{\string\t} \edef\Nc@zero{\string\0}
\edef\nc@nl{\string\n\ignorespaces}
\edef\nc@tab{\string\t\ignorespaces}
\edef\nc@zero{\string\0\ignorespaces}
%
\def\SetEscapeChars@kernel{\let\"\Nc@dq \let\'\Nc@sq \let\n\Nc@nl \let\t\Nc@tab \let\0\Nc@zero}
\def\SetnEscapeChars@kernel{\let\"\Nc@dq \let\'\Nc@sq \let\n\nc@nl \let\t\nc@tab \let\0\nc@zero} %For \ncode

% Characters that can appear in identifiers and numbers
%Token registers suffice, but having to write \the\tokregister is annoying.
\def\TcodeReloadB{
  \def\SpecialCharsInIdent{\catcode`\_=\cat@xi} %In identifiers, special to TeX
  \let\OtherCharsInIdent\empty %In identifiers, "other" to TeX. Change to, e.g., {\catcode`\$=11}, if $ is allowed within identifiers. Digits are hardcoded
						%and need not be included here. You'd need to redefine \NcodeParseWord (in Tkernel-parsecode.tex) to undo that there.
  \def\NumberCatcodes{\catcode`\_=\cat@xii \catcode`.=\cat@xi} % 11 -> 12 for chars from the two above and 11 for those not above. Add, e.g, \catcode`,=11, if it be the case.
  \let\SetEscapeChars\SetEscapeChars@kernel
  \let\SetnEscapeChars\SetnEscapeChars@kernel
}
\TcodeReloadB

% For \ident, \IDENT, \FastIdent and \Fastfid
\def\SetIdentCatcodes{\SpecialCharsInIdent\MakeDefineDollar}

%We cannot make <space> of cat. 12 because it will print the character at that position. In a fixed-width
%font, it may not be space. We do not \let =\ % because we want spaces ignored after \ignorespaces.

%For \f(ormat)code (but his will put space back to normal), \F(ormat)code \stdin and \stdout
\def\SetFcodeCatcodes{
\catcode`\ =\active \catcode`\_=\cat@xii \catcode`\#=\cat@xii \catcode`\$=\cat@xii
\catcode`\&=\cat@xii \catcode`\^=\cat@xii \catcode`\~=\cat@xii \catcode`\%=\cat@xii
\SetEscapeChars \chardef\\=`\\
}

%For \Ncode and \n(s)code
\def\MakeLettersAndOthers{
\catcode`0=\cat@xi \catcode`1=\cat@xi \catcode`2=\cat@xi \catcode`3=\cat@xi \catcode`4=\cat@xi
\catcode`5=\cat@xi \catcode`6=\cat@xi \catcode`7=\cat@xi \catcode`8=\cat@xi \catcode`9=\cat@xi
\catcode`\ =\active \catcode`\_=\cat@xii \catcode`\#=\cat@xii \catcode`\$=\cat@xii
\catcode`\&=\cat@xii \catcode`\^=\cat@xii \catcode`\~=\cat@xii \catcode`\%=\cat@xii
 \chardef\\=`\\
\SpecialCharsInIdent\OtherCharsInIdent
\catcode\c@dollar\cat@xi %\MakeDollarLetter
}

%For \Ncode
\def\SetNcodeCatcodes{\MakeLettersAndOthers\DefineDollar}
%For \ncode and \nscode
\def\SetncodeCatcodes{\MakeLettersAndOthers\DefineDollar
\let\SetEscapeChars\SetnEscapeChars
\let\MaybeSkipSpacesAfterCS\SkipSpacesAfterCS
}
