\input hyperbasics

\expandafter\edef\csname hypers@fe\endcsname{\catcode
                                             `\noexpand @=\the\catcode`\@}%
\catcode`\@=11
{\setbox0=\hbox{
\errhelp{lhyper needs a higher revision of hyperbasics.}
\ifx\hyperv@rsion\hyper@ndefined
  \errmessage{Need at least version 1 of hyperbasics. You have %
              version 0}%
  \egroup\egroup\expandafter\stop
\else
  \ifnum2>\hyperv@rsion
  \errmessage{Need at least version 1 of hyperbasics. You have %
              version \hyperv@rsion}%
  \egroup\egroup\expandafter\expandafter\expandafter\stop
  \fi
\fi}}

\let\hypernoname=\relax
% Change all places where \@currentlabel is being set. 
% Tempoarily, put a \hyperdef at precisely those points.
\def\refstepcounter#1{\stepcounter{#1}\let\@tempa\protect
\def\protect{\noexpand\protect\noexpand}%
\hyperdef\hypernoname{#1}{\csname the#1\endcsname}{}%
\edef\@currentlabel{\hyper@\hyperpr@ref\hypernoname%
                  {\csname p@#1\endcsname\csname the#1\endcsname}}%
\let\protect\@tempa}%

% Equations are special too
\def\equation{$$% $$ BRACE MATCHING HACK
\let\hyper@n@=\hyperdef
\let\hyperdef=\hyper@nique\refstepcounter{equation}%
\let\hyperdef=\hyper@n@\let\hyper@qn@=\theequation
\def\theequation{\hyperdef\hypernoname{equation}{\hyper@qn@}{\hyper@qn@}}%
}


\def\eqnarray{\stepcounter{equation}%
\global\@eqnswtrue\m@th
\global\@eqcnt\z@\tabskip\@centering\let\\\@eqncr
\let\hyper@qn@=\theequation
\hyper@nique\hypernoname{equation}{\hyper@qn@}{}%
\edef\@currentlabel{%
\hyper@\hyperpr@ref\hypernoname{\theequation}}%
$$%
\def\theequation{\hyperdef\hypernoname{equation}{\hyper@qn@}{\hyper@qn@}}%
\edef\@currentlabel{%
\hyper@\hyperpr@ref\noexpand\hypernoname{\noexpand\hyper@qn@}}%
\halign to\displaywidth\bgroup\@eqnsel\hskip\@centering
  $\displaystyle\tabskip\z@{##}$&\global\@eqcnt\@ne
  \hskip 2\arraycolsep \hfil${##}$\hfil
  &\global\@eqcnt\tw@ \hskip 2\arraycolsep $\displaystyle\tabskip\z@{##}$\hfil
   \tabskip\@centering&\llap{##}\tabskip\z@\cr}

% footnotes are special. We simply redefine all occurances of \@thefnmark.

\def\footnote{\@ifnextchar[{\@xfootnote}{\stepcounter{\@mpfn}%
     \hyper@nique\hypernoname{footnote}{\thempfn}{}%
     \begingroup\let\protect\noexpand
       \xdef\@thefnmark{{\hyper@\hyperpr@ref\hypernoname
                        {\thempfn}}}\endgroup
     \@footnotemark\@footnotetext}}
 
\def\@xfootnote[#1]{
   \hyper@nique\hypernoname{footnote}{\thempfn}{}%
   \begingroup \csname c@\@mpfn\endcsname #1\relax
   \let\protect\noexpand
   \xdef\@thefnmark{{\hyper@\hyperpr@ref\hypernoname
                    {\thempfn}}}\endgroup
   \@footnotemark\@footnotetext}

\def\footnotemark{\@ifnextchar[{\@xfootnotemark}{\stepcounter{footnote}%
     \hyper@nique\hypernoname{footnote}{\thefootnote}{}%
     \begingroup\let\protect\noexpand
       \xdef\@thefnmark{{\hyper@\hyperpr@ref\hypernoname
                        {\thefootnote}}}\endgroup
     \@footnotemark}}
 
\def\@xfootnotemark[#1]{\begingroup \c@footnote #1\relax
     \hyper@nique\hypernoname{footnote}{\thefootnote}{}%
   \let\protect\noexpand
   \xdef\@thefnmark{{\hyper@\hyperpr@ref\hypernoname
                    {\thefootnote}}}\endgroup \@footnotemark}
 
\def\footnotetext{\@ifnextchar [{\@xfootnotenext}%
   {\begingroup\let\protect\noexpand
     \hyper@nique\hypernoname{footnote}{\thempfn}{}%
      \xdef\@thefnmark{{\hyper@\hyperpr@ref\hypernoname
                       {\thempfn}}}\endgroup
    \@footnotetext}}
 
\def\@xfootnotenext[#1]{\begingroup \csname c@\@mpfn\endcsname #1\relax
   \let\protect\noexpand
     \hyper@nique\hypernoname{footnote}{\thempfn}{}%
   \xdef\@thefnmark{{\hyper@\hyperpr@ref\hypernoname
                    {\thempfn}}}\endgroup \@footnotetext}
 

% The footnote has to be defined when insertion being generated.
\def\hyper@eat#1\hyperpr@ref#2#3#4#5{#5}%
\def\hyperstr@pcurly#1{#1}%
\long\def\@footnotetext#1{\insert\footins{\reset@font\footnotesize
    \interlinepenalty\interfootnotelinepenalty
    \splittopskip\footnotesep
    \splitmaxdepth \dp\strutbox \floatingpenalty \@MM
    \hsize\columnwidth \@parboxrestore
   \edef\@currentlabel{\csname p@footnote\endcsname\@thefnmark}%
    {\edef\@thefnmark{\expandafter\expandafter\expandafter
                      \hyper@eat\expandafter\hyperstr@pcurly\@thefnmark}%
     \edef\@thefnmark{\noexpand\hyperdef\noexpand\hypernoname{footnote}%
     {\@thefnmark}{\@thefnmark}}%
     \@makefntext
     {\rule{\z@}{\footnotesep}\ignorespaces
      #1\strut}}}}

% Similarly references are special
\def\@lbibitem[#1]#2{\item[{\def\protect{}\xdef\hypert@mp{#1}}%
                            \edef\hypert@mp{\hypert@mp}%
                            \edef\hypert@mp{\hypert@mp}%
                           \hyperdef\hypernoname{reference}{\hypert@mp}%
                           {\@biblabel{#1}}\global\let\hypert@mp=\relax\hfill]\if@filesw
      {\def\protect##1{\string ##1\space}\immediate
       \write\@auxout{\string\bibcite{#2}{#1}}}\fi\ignorespaces}

\def\@bibitem#1{\@noitemargtrue\@item
                [\hyperdef\hypernoname{reference}{\the\value{\@listctr}}%
                {\the\value{\@listctr}}]\if@filesw \immediate\write\@auxout
       {\string\bibcite{#1}{\the\value{\@listctr}}}\fi\ignorespaces}
 
\def\bibcite#1#2{\expandafter\xdef\csname b@#1\endcsname{\hyper@\hyperpr@ref
                 {}{reference}{#2}{#2}}%
                 \expandafter\gdef\csname hyperb@#1\endcsname{#2}}
 

%
% Sectioning macros
%
\def\@sect#1#2#3#4#5#6[#7]#8{\ifnum #2>\c@secnumdepth
     \let\@svsec\@empty\else
     \let\hyper@n@=\hyperdef
     \let\hyperdef=\hyper@nique
     \refstepcounter{#1}%
     \let\hyperdef=\relax\let\hypernoname=\relax
     \edef\@svsec{\hyperdef\hypernoname{#1}%
       {\csname the#1\endcsname}{\csname the#1\endcsname\hskip 1em}}%
     \let\hyperdef=\hyper@n@\fi
     \@tempskipa #5\relax
      \ifdim \@tempskipa>\z@
        \begingroup #6\relax
          \@hangfrom{\hskip #3\relax\@svsec}{\interlinepenalty \@M #8\par}%
        \endgroup
       \csname #1mark\endcsname{#7}\addcontentsline
         {toc}{#1}{\ifnum #2>\c@secnumdepth \else
                      \protect\numberline{\hyper@\hyperpr@ref\hypernoname
                      {\hbox{\hskip1pt\relax\csname the#1\endcsname}%
                       }\hskip-1pt\relax}\fi
                    #7}\else
        \def\@svsechd{#6\hskip #3\relax  %% \relax added 2 May 90
                   \@svsec #8\csname #1mark\endcsname
                      {#7}\addcontentsline
                           {toc}{#1}{\ifnum #2>\c@secnumdepth \else
                             \protect\numberline{\hyper@\hyperpr@ref\hypernoname
                           {\hbox{\hskip1pt\relax\csname the#1\endcsname}%
                            }\hskip-1pt\relax}\fi
                       #7}}\fi
     \@xsect{#5}}

%
% Captions
%
\def\caption{\let\hyper@n@=\hyperdef
             \let\hyperdef=\hyper@nique
             \refstepcounter\@captype
             \let\hyperdef=\hyper@n@
             \@dblarg{\@caption\@captype}}
\long\def\@caption#1[#2]#3{\par\begingroup
    \@parboxrestore
    \normalsize
    \@makecaption{\hyperdef\hypernoname{#1}{\csname the#1\endcsname}%
                  {\csname fnum@#1\endcsname}}{\ignorespaces #3}\par
    \addcontentsline{\csname
    ext@#1\endcsname}{#1}{\protect\numberline{\csname
    the#1\endcsname}{\ignorespaces #2}}%
  \endgroup}

%
% toc 
%
\def\@outputpage{\begingroup\catcode`\ =10
     \let\-\@dischyph \let\'\@acci \let\`\@accii \let\=\@acciii
    \if@specialpage
     \global\@specialpagefalse\@nameuse{ps@\@specialstyle}\fi
     \if@twoside
       \ifodd\count\z@ \let\@thehead\@oddhead \let\@thefoot\@oddfoot
            \let\@themargin\oddsidemargin
          \else \let\@thehead\@evenhead
          \let\@thefoot\@evenfoot \let\@themargin\evensidemargin
     \fi\fi
     \shipout
     \vbox{\reset@font %% RmS 91/08/15
           \normalsize \baselineskip\z@ \lineskip\z@
           \let\par\@@par %% 15 Sep 87
           \vskip \topmargin \moveright\@themargin
           \vbox{\setbox\@tempboxa
                   \vbox to\headheight{\vfil \hbox to\textwidth
                                       {\let\label\@gobble \let\index\@gobble
                                        \let\glossary\@gobble %% 21 Jun 91
                                        {\edef\thepage{\noexpand\hyperdef
                                         \noexpand\hyperj@nk
                                         {page}{\thepage}{\thepage}}%
                                         \@thehead}}}% %% 22 Feb 87
                 \dp\@tempboxa\z@
                 \box\@tempboxa
                 \vskip \headsep
                 \box\@outputbox
                 \baselineskip\footskip
                 \hbox to\textwidth{\let\label\@gobble
                           \let\index\@gobble  %% 22 Feb 87
                           \let\glossary\@gobble %% 21 Jun 91
                           {\edef\thepage{\noexpand\hyperdef
                            \noexpand\hyperj@nk{page}{\thepage}{\thepage}}%
                            \@thefoot}%
                           }}}\global\@colht\textheight
           \endgroup\stepcounter{page}\let\firstmark\botmark}


\edef\contentsline#1#2#3{\noexpand\hyper@nique\noexpand\hypernoname
                         {page}{#3}{}%                         
                         \noexpand\csname l@#1\noexpand\endcsname{#2}%
                         {\hyper@\hyperpr@ref\noexpand\hypernoname{#3}}}

% Some style files change this setup. After loading a style file check if
% the corresponding .hty file exists. Load it in that case.
\newread\hyper@inputcheck
\def\hyper@nput #1.sty{\input #1.sty\relax
                       \immediate\openin\hyper@inputcheck #1.hty\relax
                       \ifeof\hyper@inputcheck\relax
                         \immediate\closein\hyper@inputcheck\relax
                       \else\immediate\closein\hyper@inputcheck\relax
                         \input #1.hty\relax
                       \fi}%
\def\@documentstyle[#1]#2{\makeatletter
   \def\@optionlist{#1}\gdef\@optionfiles{}\hyper@nput #2.sty\relax
   \let\@elt\hyper@nput \@optionfiles \let\@elt\relax \makeatother}
 
\def\hyper@pen#1{\immediate\openin\hyper@inputcheck #1.hty\relax
                 \ifeof\hyper@inputcheck\relax
                   \immediate\closein\hyper@inputcheck\relax
                 \else\immediate\closein\hyper@inputcheck\relax
                   \input #1.hty\relax
                 \fi}

\def\enddocument{\@checkend{document}\clearpage\begingroup
\if@filesw \immediate\closeout\@mainaux
\def\global\@namedef##1##2{}\def\newlabel{\@testdef r}%
\def\bibcite{\@testdef {hyperb}}\@tempswafalse \makeatletter\input \jobname.aux
\if@tempswa \@@warning{Label(s) may have changed.  Rerun to get
cross-references right}\fi\fi\endgroup\deadcycles\z@\@@end}

\hypers@fe
\endinput
% Leave this line in the file

.
