%This file removes the token \TcodeLang from some macros from the kernel.
% In particular, from the ones involved in \@parsecode and the inline environments that don't use \@parsecode.

%If the user is removeing \TcodeLang, its code cannot possibly work if this is not done:
\def\ThisIsLanguage#1{}

\count255=\catcode`@
\catcode`@=11

\edef\next{%Note the extra pair of { } and the <space> before #2.
\unexpanded{\def\strip@TcodeLang #1}\string\TcodeLang\unexpanded{ #2\strip@TcodeLang{{#1#2}}}
}
\next
\edef\next{\unexpanded{\def\strip@TcodeLang@two #1}\string\TcodeLang\unexpanded{ #2}\string\TcodeLang\unexpanded{ #3\strip@TcodeLang{{#1#2#3}}}}
\next

%For macros that take no argument
\def\stripTcodeLang#1{
  \edef\next{\exP\detokenize\exP{#1}}
  \toks0\exP\strip@TcodeLang\next\strip@TcodeLang
  \def\next##1{\toks0 \scantokens{##1}}
  \exP\next\exP{\the\toks0}
  \exP\def\exP#1\exP{\the\toks0}
}

%For macros that take one and two arguments.
% We strip the last line to a separate macro: \exP\def\exP#1\exP##\exP1\exP{\the\toks0}.
% TeX remembers the char used in place of #. If it is *, that is what a user will see in debug
% output and when wrting \show\stripTcodeLang@i, and that might be confusing.
\catcode`#=12
\catcode`*=6
\def\stripTcodeLang@toks@i*1{
  \edef\next{\exP\detokenize\exP{*1{#1}}}
  \toks0\exP\strip@TcodeLang\next\strip@TcodeLang
  \def\next**1{\toks0 \scantokens{{**1}}}
  \exP\next\exP{\the\toks0}
}

%This one strips two TcodeLang's
\def\stripTcodeLang@toks@ii*1{
  \edef\next{\exP\detokenize\exP{*1{#1}{#2}}}
  \toks0\exP\strip@TcodeLang@two\next\strip@TcodeLang
  \def\next**1{\toks0 \scantokens{{**1}}}
  \exP\next\exP{\the\toks0}
}
\catcode`#=6
\catcode`*=12

%We cannot just write \edef#1##1{\the\toks0} for TeX's "wrong" decision w.r.t. duplication of #.
\def\stripTcodeLang@i#1{\stripTcodeLang@toks@i#1
  \exP\def\exP#1\exP##\exP1\exP{\the\toks0}
}
\def\stripTcodeLang@ii#1{\stripTcodeLang@toks@ii#1
  \exP\def\exP#1\exP##\exP1\exP##\exP2\exP{\the\toks0}
}

%The next lines, because of \scantokens
\edef\Tcode@restore@settings{\everyeof={\the\everyeof}}
\everyeof={}

%These are the more important ones
\stripTcodeLang@i\fcode
\stripTcodeLang@i\Fcode
\stripTcodeLang@i\ident@
\stripTcodeLang@i\IDENT@
\stripTcodeLang@i\FastIdent@
\stripTcodeLang@i\HookAndPrintWord
\stripTcodeLang@i\NcodeNoLetter
\stripTcodeLang@i\NcodeNoLetter %There are two in this macro

\stripTcodeLang@i\IfWordKnown
\stripTcodeLang@i\MultiLineFormat
\stripTcodeLang@i\csFormat % These two may also
\stripTcodeLang@i\@FormatToApply %be important
\ifx\MakeWord\MakeWordFast \stripTcodeLang@ii\MakeWord
\else\ifx\MakeWord\MakeWordSlow \stripTcodeLang@ii\MakeWord
\fi\fi
\stripTcodeLang@ii\MakeWordFast
\stripTcodeLang@ii\MakeWordSlow
\stripTcodeLang@ii\MakeWordIndirect

\Tcode@restore@settings

\catcode`@=\count255
