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

%%%%%%%%%%*******  Some useful utilities, not really part of the core  *******%%%%%%%%%%
% -----------------------------------------------------------------------------------------------------------------

%%%**** Make @ a escape char within comments, or elsewhere. ****%%%

% \@ produces a normal @. @@ processes the second @ as the argument of the first.
%We do not parametrize the character used for escaping. If you want a different one, just copy-pase the code and change @
%by the character you want.
%See Tcode_Ccode.tex or Tcode_pycode.tex for an example of how to use \MakeAtEscape

\count255=\catcode`@
\catcode`@=12 \def\OrigAtSign{@} %Save the original @
\catcode`@=13
\def\MakeAtEscape{\catcode`@\active \let\@\OrigAtSign \let@\AtEscape} %To be placed, e.g., in the setup of comments. It makes @ equal to AtEscape
\def\AtEscape#1{\let@\OrigAtSign{\FormatAtEsc{#1}}\let@\AtEscape} %First redefines @ in case it appears as part of its argument; then processes the argument; then restores @
\catcode`@=\count255
% The default definition of \FormatAtEsc is in Tkernel-lang.tex


%%%**** Hooks that only do something for known words ****%%%

%% Test an identifier, whether it is known or not
\protected\def\IfWordKnown#1{\ifcsname Format\TcodeLang @#1\endcsname} % e.g. \IfWordKnown{bessel} <some code> \else <other code> \fi

% A PrePrintHook that ignores the unkown words. In order to use it write \let\PrePrintHook\HookOnlyKnown
% and provide some definition for \KnownWordHook. Recall that these use \WordToPrint and \FormatToApply.
\def\HookOnlyKnown{\unless\ifx\FormatToApply\undefined\KnownWordHook\fi}
%The same, but in addition pass the expanded \FormatToApply as argument to \ProcessKnown word.
\def\HookOnlyKnownE{\unless\ifx\FormatToApply\undefined \exP\ProcessKnownWord\exP{\FormatToApply}\fi} %Expanded once
\def\HookOnlyKnownEE{\unless\ifx\FormatToApply\undefined \edef\next{{\FormatToApply}}\exP\ProcessKnownWord\next\fi} %Espanded in \edef
%
\let\KnownWordHook\PrePrintDoNothing
\let\KnownWordDoNothing\PrePrintDoNothing

%%%**** Other ****%%%

%\relax, to kill \ignorespaces coming from \color.
\def\MultiLineFormat#1{\xdef\CContinueInTheMiddle{\exP\expandonce\csname Format\TcodeLang #1\endcsname\relax}\CContinueInTheMiddle}
% If <space> were =\ , or \def {\ } we could spare the '\relax'. But we <space> is \space; i.e., { }.
%\def\MultiLineFormat#1{\exP\global\exP\let\exP\CContinueInTheMiddle\csname Format\TcodeLang #1\endcsname \CContinueInTheMiddle}
