%%% Direct font selection bypassing LaTeX's NFSS bookkeeping.

% The 'C' stand for Ccode, the original motivation for this design.

%We use /sl/ instead of /it/ because we expect this to be used more with fixed-width fonts,
% for which slanted is more common. \italics is useful in practice; It may select true italics, or any other fifth variant.
%
%The selection of bold variants (\Cbold and \itlight) sould use \csname bfseries@\f@family\endcsname
% that can expand to either 'b' or 'bx', in place of a literal 'b'.  Because this macros are intended mostly for tt-fonts,
% writing \bfseries@tt, that also expands to 'b' or 'bx' will work in practice and takes the macro half the
% time to fully expand. But because a fixed width font can have a 'b' variant but cannot have a 'bx' one,
% we write directlly 'b'. It is very likely that if you use \Cbold or \itbold for other families it will work, too.

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

\ifdefined\DeclareFontEncoding
\protected\def\Clight{\csname \f@encoding/\f@family/m/n/\f@size\endcsname}
\protected\def\Cbold{\csname \f@encoding/\f@family/b/n/\f@size\endcsname}
\protected\def\itlight{\csname \f@encoding/\f@family/m/sl/\f@size\endcsname}
\protected\def\itbold{\csname \f@encoding/\f@family/b/sl/\f@size\endcsname}
\protected\def\italics{\csname \f@encoding/\rmdefault/m/it/\f@size\endcsname}
\fi

%For these definitions to work, the font must have been selected in the usual way at least once.
%"Selected" does not mean "used".

\ifdefined\AtBeginDocument

%This will activate the fonts, in the current family
\def\ActivateFontsOfFamily{
{\upshape\mdseries
{\normalsize{\itshape\slshape}\bfseries\slshape}%
{\small{\itshape\slshape}\bfseries\slshape}%
{\footnotesize{\itshape\slshape}\bfseries\slshape}%
{\scriptsize{\itshape\slshape}\bfseries\slshape}%
{\large{\itshape\slshape}\bfseries\slshape}%
}}

\AtBeginDocument{
  \ActivateFontsOfFamily
  {\ttfamily\let\itshape\relax\ActivateFontsOfFamily\DoSelectCodeFontII}
}
\let\DoSelectCodeFontII\relax

%We hook into the \SelectCodeFont to replace its default (=\ttfamily) by a bold setting
% of \f@encoding and \f@family, then select \Clight
\ifdefined\SelectCodeFont
%If \SelectCodeFont is defined, then so is \exP as \expandafter
\def\DoSelectCodeFontII{
  \escapechar=-1 \edef\thettfont{\exP\string\the\font}
  \def\next##1/##2/##3/##4/##5\relax{\toks0={\def\f@encoding{##1}\def\f@family{##2}}}\exP\next\thettfont\relax
  \xdef\SelectCodeFont{\the\toks0 \Clight}
}
\fi

\fi %\AtBeginDocument

\catcode`@=\count255