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

%%% The environments  «» and ‹›. This are the only NoLetter's that are handled by default %%%

% Because pdftex does not handle utf-8 input we need some horrible definitions to define
% the environments «» and ‹›. The macro \@parsecode will absorb the first byte of its utf-8 representation
% The definitions would be very easy if we just wrote this file in any 8-bit 1byte-1char enconding. We would
% just place the characters represented by C2, BA, BB, etc. But that may cause problems if
% someone atempts to read this file with a viewer assuming utf-8 input and tries to "fix" it.

% utf-8: « C2 AB.  » C2 BB
% ‹ e2 80 b9. › e2 80 ba

%Define two macros to expand to the caracter C2 and and e2 respectively, with cat. 12
%In LuaTeX the macros simply expand to « and ‹
\def\NcodeKeepFirst#1#2\relax{#1}
{\catcode"C2=12 \global\edef\charCii{\NcodeKeepFirst«\relax}} % C2
{\catcode"E2=12 \global\edef\charEii{\NcodeKeepFirst‹\relax}} % E2

%Parsing « » and ‹ › The first byte of « resp. ‹ has already been consumed.
\def\NcodeParseEscape{\bgroup\catcode`\{=1 \catcode`\}=2 \catcode`\ =10 \DoParseEscape}
\def\NcodeReParseEscape{\bgroup\catcode`\{=1 \catcode`\}=2 \catcode`\ =10 \DoReParseEscape}
%
\ifx«« %If we are using native utf-8 input
  \catcode`»=13
  \def\DoParseEscape{\catcode`»=\active \def»{\egroup\@parsecode}} %Do nothing. Just make » close the group and restart parsing
  \def\DoReParseEscape#1›{\global\edef\Nc@deExp{#1}\egroup\exP\@parsecode\Nc@deExp}
  \catcode`»=12
\else
  \def\DoParseEscape#1#2»{#2\egroup\@parsecode} %#1 should be AB. We cannot place that byte in the input file
  \def\DoReParseEscape#1#2#3›{\global\edef\Nc@deExp{#3}\egroup\exP\@parsecode\Nc@deExp} %#1#2 should be 80 b9.
\fi
% With proper utf-8 input, «, etc. have catcode=12. In that case «» and ‹› can be made to work inside
% strings and comments by making « and ‹ active characters.

% \NcodeNoLetter@<dollarchar>=\NcodeSMark is done by SetUpDollar
\exP\let\csname NcodeNoLetter@\charCii\endcsname=\NcodeParseEscape
\exP\let\csname NcodeNoLetter@\charEii\endcsname=\NcodeReParseEscape
