%%% ======================================================================
%%%  @LaTeX-style{
%%%     filename        = "labels.sty",
%%%     version         = "1.0",
%%%     date            = "17 July 1992",
%%%     time            = "13:39:24.74 +0100",
%%%     author          = "Norman Gray",
%%%     address         = "Department of Physics
%%%                        Open University
%%%                        Milton Keynes
%%%                        MK7 6AA, UK",
%%%     e-mail          = "N.O.Gray@open.ac.uk (Internet)",
%%%     telephone       = "+44 908 652279",
%%%     FAX             = "+44 908 653744",
%%%     archived        = "Aston, SHSU",
%%%     keywords        = "Labels, cross-referencing",
%%%     abstract        = "If this style file is included amongst the
%%%                        \documentstyle options, all uses of the \label
%%%                        command within the LaTeX file will have the label
%%%                        name printed in the margin (except when used in
%%%                        a \caption, when it appears in the text).",
%%%     codetable       = "ISO/Ascii",
%%%     checksum        = "60488 80 330 3319",
%%%     docstring       = "Display label names in margin
%%%                        
%%%                        The checksum field above contains a CRC-16
%%%                        checksum as the first value, followed by the
%%%                        equivalent of the standard UNIX wc (word 
%%%                        count) utility output of lines, words, and
%%%                        characters.  This is produced by Robert 
%%%                        Solovay's checksum utility."
%%% }
%%% ======================================================================

\message{Labels V 1.1 adopted by Kay Wiese after Norman Gray}
\let\@@eqnnum=\@eqnnum
\def\@eqnnum{\@@eqnnum
% + |\@eqnnum| will produce a note, sticking into the margin beside
% the equation number, which has the equation's label and number.
% |\labeln@me| is initialised to |\relax|, redefined within the
% |\label| macro, and reset to |\relax| here.  If it's already equal
% to |\relax| here, the equation number hasn't been labelled, and so
% `???' is put in the margin. \-
\if\labeln@me\relax
%  \margintext{???}%
 \margintext{}%
\else
   \margintext{\labeln@me}\global\def\labeln@me{\relax}%
\fi}

\let\@@makecaption\@makecaption
\let\@label\label
\def\@gobblethree#1#2#3{}
\def\prlabelname#1{% expansion is label name #1 with all catcodes `other'
\expandafter\expandafter\expandafter\@gobblethree
    \expandafter\string\csname r@#1\endcsname}
    % use \r@#1, rather then just \#1 to avoid defining new control sequence

\long\def\@makecaption#1#2{{\def\label##1{{\nintt\{\prlabelname{##1}\}\space
    }\@label{##1}}\@@makecaption{#1}{#2}}}
\def\label#1{\@bsphack\@label{#1}%
\ifmmode
  \xdef\labeln@me{\prlabelname{#1}}%  label name produced with equation number
\else
{\setbox0=\vbox to 0pt{\vss\hbox to \hsize{\hfill
    \margintext{\prlabelname{#1}}}}\dp0=0pt%
\ifvmode
  \nointerlineskip\box0\nobreak	    % fix this box to next one
\else
  \vadjust{\box0\nobreak}%
\fi}%
\fi
\@esphack}

%\if@twoside
%  \def\margintext#1{\ifodd\c@page\rlap{\nintt\quad\{#1\}}\else
%    \llap{\nintt\{#1\}\quad\hskip\textwidth}\fi}
%\else
%  \def\margintext#1{\rlap{\nintt\quad\{#1\}}}
%\fi
%\def\margintext#1{\rlap{\sevit\quad\{#1\}}}
\def\margintext#1{\rlap{\ \begin{minipage}{1.7cm}\scriptsize \sf #1 \end{minipage}}}
\global\def\labeln@me{\relax}

\def\bibitem{\@ifnextchar[{\@lbibitem}{\@bibitem}}
 
%% RmS 92/02/26: Added \hfill to restore left-alignment of
%%               bibliography labels in alpha style
\def\@lbibitem[#1]#2{\item[\@biblabel{#1}\hfill]\if@filesw
      {\def\protect##1{\string ##1\space}\immediate
       \write\@auxout{\string\bibcite{#2}{#1}}}\fi\ignorespaces}
%% Placement of `}' in def of \@lbibitem corrected 29 Apr 87
%% (Error found by Arthur Ogawa.)

%% RmS 91/11/13: Changed counter enumi to enumiv,
%%               as it says in the comment above
%% RmS 92/01/10: Changed \c@enumiv to \value{\@listctr}.
\def\@bibitem#1{\item\if@filesw \immediate\write\@auxout
       {\string\bibcite{#1}{\the\value{\@listctr}}}
\leftline{\scriptsize\sf\prlabelname{#1}}
\vspace{-2mm}
\fi\ignorespaces}
