% This is the file citehack.sty of the T2 package.
%
% Allow inputenc-generated characters as references in \cite and \bibitem.
% Also in \label and \ref.

\ProvidesPackage{citehack}

\let\org@IeC\IeC
\def\tmp@IeC#1{\string\IeC\space{\string#1 }}

% This is a modified \@bibitem command;
% we added \let\protect\noexpand, like in \@lbibitem,
% because the item may include, e.g., \IeC {...}
% or some other protected commands.
\def\@bibitem#1{\item\if@filesw {\let\protect\noexpand\immediate\write\@auxout
       {\string\bibcite{#1}{\the\value{\@listctr}}}}\fi\ignorespaces}
%\def\@lbibitem[#1]#2{\item[\@biblabel{#1}\hfill]\if@filesw
%      {\let\protect\noexpand\let\IeC\tmp@IeC
%       \immediate
%       \write\@auxout{\string\bibcite{#2}{#1}}}\fi\ignorespaces}
%\def\@bibitem#1{\item\if@filesw \let\IeC\tmp@IeC\immediate\write\@auxout
%       {\string\bibcite{#1}{\the\value{\@listctr}}}\let\IeC\org@IeC\fi\ignorespaces}

\def\@citex[#1]#2{\let\IeC\tmp@IeC\edef\CH@temp{#2}\let\IeC\org@IeC
  \let\@citea\@empty
  \@cite{\@for\@citeb:=\CH@temp\do
    {\@citea\def\@citea{,\penalty\@m\ }%
     \edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
     \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
     \@ifundefined{b@\@citeb}{\mbox{\reset@font\bfseries ?}%
       \G@refundefinedtrue
       \@latex@warning
         {Citation `\@citeb' on page \thepage \space undefined}}%
       {\hbox{\csname b@\@citeb\endcsname}}}}{#1}}

\def\nocite#1{\@bsphack
  \let\IeC\tmp@IeC\edef\CH@temp{#1}\let\IeC\org@IeC
  \@for\@citeb:=\CH@temp\do{%
    \edef\@citeb{\expandafter\@firstofone\@citeb}%
    \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
    \@ifundefined{b@\@citeb}{\G@refundefinedtrue
        \@latex@warning{Citation `\@citeb' undefined}}{}}%
  \@esphack}

\def\@newl@bel#1#2#3{\let\IeC\tmp@IeC
  \@ifundefined{#1@#2}%
    \relax
    {\gdef \@multiplelabels {%
       \@latex@warning@no@line{There were multiply-defined labels}}%
     \@latex@warning@no@line{Label `#2' multiply defined}}%
  \global\@namedef{#1@#2}{#3}\let\IeC\org@IeC}

% This is a modified \@testdef command taken from Babel:
\def\@testdef #1#2#3{%
  \let\IeC\tmp@IeC
  \expandafter\let\expandafter\bbl@tempa\csname #1@#2\endcsname
  \def\bbl@tempb{#3}%
  \ifx\bbl@tempa\relax\else
  \edef\bbl@tempa{\expandafter\strip@prefix\meaning\bbl@tempa}\fi
  \edef\bbl@tempb{\expandafter\strip@prefix\meaning\bbl@tempb}%
  \ifx \bbl@tempa \bbl@tempb
  \else \@tempswatrue \fi\let\IeC\org@IeC}

% \ref, \pageref and \label support:
\DeclareRobustCommand\ref[1]{\let\IeC\tmp@IeC
  \expandafter\let\expandafter\CH@temp\csname r@#1\endcsname
  \let\IeC\org@IeC\@setref\CH@temp\@firstoftwo{#1}}
\DeclareRobustCommand\pageref[1]{\let\IeC\tmp@IeC
  \expandafter\let\expandafter\CH@temp\csname r@#1\endcsname
  \let\IeC\org@IeC\@setref\CH@temp\@secondoftwo{#1}}
\def\label#1{\let\IeC\tmp@IeC
  \@bsphack\protected@write\@auxout{}{\string\newlabel{#1}{{\@currentlabel}{\thepage}}}\@esphack
  \let\IeC\org@IeC}

% varioref package support:
\def\vref@pagenum#1#2{\let\IeC\tmp@IeC
  \@ifundefined{r@#2}{\@namedef{r@#2}{{??}{??}}}{}%
  \edef#1{\expandafter\expandafter\expandafter
                \@cdr\csname r@#2\endcsname
                \@nil}%
  \let\IeC\org@IeC}
\def\vrefpagenum#1#2{\let\IeC\tmp@IeC
  \@ifundefined{r@#2}%
    {\G@refundefinedtrue
     \@latex@warning{Reference `#2' on page \thepage \space
             undefined}}{}%
  \let\IeC\org@IeC
  \vref@pagenum{#1}{#2}}
