%%
%% This is file `showlabels.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% showlabels.dtx  (with options: `package')
%% Showlabels: Style to display labels in the margin
%% This is the showlabels package
%%
%% This software is copyright, 1999, 2001--2004, Norman Gray.
%%
%% This program is free software; you can redistribute it and/or
%% modify it under the terms of the GNU General Public License
%% as published by the Free Software Foundation; either version 2
%% of the License, or (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; if not, write to the Free Software
%% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
%%
%% Author: Norman Gray, norman@astro.gla.ac.uk.
%% Department of Physics and Astronomy, University of Glasgow, UK
%%
%% See the file LICENCE for a copy of the GPL.
%% You can also find an online copy at http://www.gnu.org/copyleft/gpl.html .
%%
%% $Id: showlabels.dtx,v 1.24 2004/10/08 18:48:22 norman Exp $
%%
\def\ParseRCSDate$#1: #2 #3 ${\def\SL@Date{#2}}
\ParseRCSDate$Date: 2004/10/08 18:48:22 $
\def\filename{showlabels}
\def\fileversion{1.5}  %%VERSION%%
\def\filedate{\SL@Date}
\def\docdate{\SL@Date}
\def\filemaintainer{norman@astro.gla.ac.uk}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{showlabels}[\filedate\space v\fileversion]
\typeout{Package: `showlabels' v\fileversion\space<\filedate>}
\newif\ifSL@AMS
\expandafter\ifx\csname maketag@@@\endcsname\relax
  \SL@AMSfalse
\else
  \SL@AMStrue
  \typeout{with amsmath equation tags}
\fi
\ifSL@AMS
  \let\SL@maketag@@@=\maketag@@@
  \def\maketag@@@#1{\SL@maketag@@@{#1}%
  \ifx\df@label\@empty
  \else
    \SL@eqnlrtext{\df@label}%
  \fi}
\else
  \let\SL@eqnnum=\@eqnnum
  \def\@eqnnum{\SL@eqnnum
  \expandafter\ifx\SL@labelname\relax
  \else
    \SL@eqnlrtext{\SL@labelname}%
    \global\def\SL@labelname{\relax}%
  \fi}
  \global\def\SL@labelname{\relax}
\fi
\providecommand{\showlabelfont}{\small\tt}
\providecommand{\showlabelsetlabel}[1]{\normalfont\showlabelfont #1}
\def\SL@gobblethree#1#2#3{}
\def\SL@prlabelname#1{%
\expandafter\expandafter\expandafter\SL@gobblethree
    \expandafter\string\csname r@#1\endcsname}
\def\showlabels#1{%
  \@temptokena=\expandafter{\csname #1\endcsname}
  \expandafter\edef\csname SL@init#1\endcsname{%
    \let\csname SL@orig#1\endcsname\the\@temptokena
    \let\the\@temptokena\csname SL@#1\endcsname}
  \AtBeginDocument{\csname SL@init#1\endcsname}%
  \expandafter\def\csname SL@#1\endcsname{\SL@showlabels{#1}}
}
\def\SL@showlabels#1#2{%
  \@bsphack
  \SL@setlabel{#2}\relax
  \ifhmode \spacefactor\@savsf \ifdim\@savsk>\z@ \hskip1sp \fi\fi
  \csname SL@orig#1\endcsname{#2}%
}
\def\SL@initmakecaption{%
  \let\SL@origmakecaption\@makecaption
  \def\@makecaption##1##2{{%
    \let\SL@setlabel\SL@inlinetext\SL@origmakecaption{##1}{##2}}}}
\AtBeginDocument{\SL@initmakecaption}
\def\SL@margtext#1{%
  \ifmmode
    \ifSL@AMS\else
      \xdef\SL@labelname{\SL@prlabelname{#1}}%
    \fi
  \else
    \setbox\@tempboxa=\vbox to 0pt{\vss
      \hbox to \hsize{\SL@lrtext{#1}}}%
    \dp\@tempboxa\z@
    \ifvmode
      \@tempdima=\prevdepth
      \nointerlineskip\box\@tempboxa\nobreak
      \prevdepth=\@tempdima
    \else
      \vadjust{\box\@tempboxa\nobreak}%
    \fi
  \fi
}
\def\SL@inlinetext#1{%
\ifmmode
  \ifSL@AMS\else
    \xdef\SL@labelname{\SL@prlabelname{#1}}%
  \fi
\else
  \SL@interlinetextright{#1}%
\fi
}
\def\SL@interlinetextleft{\SL@setlefttrue\SL@interlinetext}
\def\SL@interlinetextright{\SL@setleftfalse\SL@interlinetext}
\def\SL@interlinetext#1{%
  \setbox\@tempboxa=\hbox{\showlabelsetlabel{#1}}\dp\@tempboxa\z@
  \ifvmode
    \nointerlineskip\vbox to 0pt{\vss
      \hbox to \columnwidth{\hss \box\@tempboxa}}%
  \else
    \ifSL@setleft
      \hbox to 0pt{%
\hss
\vbox to 0pt{\vss
  \hbox to 0pt{\hss\box\@tempboxa}%
  \hrule width 0.05em height 1.5ex depth 0pt
}}%
    \else
      \hbox to 0pt{%
\vbox to 0pt{\vss
  \box\@tempboxa
  \hrule width 0.05em height 1.5ex depth 0pt
}\hss}%
    \fi
    \penalty10000
  \fi
}
\def\SL@margintext#1{{\showlabelsetlabel{\{\SL@prlabelname{#1}\}}}}
\def\SL@righttext#1{\hfill\rlap{\quad\SL@margintext{#1}}}
\def\SL@lefttext #1{\llap{\SL@margintext{#1}\quad}\hfill}
\newif\ifSL@setleft
\def\SL@setLR{%
  \ifcase\SL@labelposition
    % 0=outer margin
    \ifodd\c@page
      \SL@setleftfalse
    \else
      \SL@setlefttrue
    \fi
  \or
    % 1=inner margin
    \ifodd\c@page
      \SL@setlefttrue
    \else
      \SL@setleftfalse
    \fi
  \or
    % 2=left margin
    \SL@setlefttrue
  \or
    % 3=right margin
    \SL@setleftfalse
  \else
    \SL@canthappen{Impossible labelposition \the\SL@labelposition}
    \SL@labelposition=3 % put everything in the right-margin for now
    \SL@setleftfalse
  \fi
}
\def\SL@alternatetext{%
  \SL@setLR
  \ifSL@setleft
    \let\SL@next\SL@lefttext
  \else
    \let\SL@next\SL@righttext
  \fi
  \SL@next
}
\def\SL@twocoltext{%
  \if@firstcolumn
    \let\SL@next\SL@lefttext
  \else
    \let\SL@next\SL@righttext
  \fi
  \SL@next}
\def\SL@eqnrighttext#1{\rlap{\quad\SL@margintext{#1}}}
\def\SL@eqnlefttext #1{\hbox to 0pt{\kern -\columnwidth
\llap{\SL@margintext{#1}\quad}\hss}}
\def\SL@eqnalternatetext{%
  \SL@setLR
  \ifSL@setleft
    \let\SL@next\SL@eqnlefttext
  \else
    \let\SL@next\SL@eqnrighttext
  \fi
  \SL@next
}
\def\SL@eqntwocoltext{%
  \if@firstcolumn
    \let\SL@next\SL@eqnlefttext
  \else
    \let\SL@next\SL@eqnrighttext
  \fi
  \SL@next}
\def\SL@canthappen#1{%
    \PackageError{showlabels}{#1}
        {This shouldn't happen -- the package showlabels has a bug.
        \MessageBreak
        Please report this, if possible with a sample document which
        \MessageBreak
        demonstrates the problem, to \filemaintainer.  Thanks.}}
\newcount\SL@labelposition
\SL@labelposition=0
\DeclareOption{outer}{\SL@labelposition=0}
\DeclareOption{inner}{\SL@labelposition=1}
\DeclareOption{left}{\SL@labelposition=2}
\DeclareOption{right}{\SL@labelposition=3}
\DeclareOption{marginal}{\let\SL@setlabel\SL@margtext}
\DeclareOption{inline}{\let\SL@setlabel\SL@inlinetext}
\let\SL@setlabel\SL@margtext
\newif\if@showlabellabel
\@showlabellabeltrue
\DeclareOption{nolabel}{\@showlabellabelfalse}
\DeclareOption{final}{\let\showlabels\@gobble}
\DeclareOption{draft}{}
\ProcessOptions
\if@twocolumn
  \let\SL@lrtext\SL@twocoltext
  \let\SL@eqnlrtext\SL@eqntwocoltext
\else
  \ifcase\SL@labelposition
    % 0=outer margin
    \if@twoside
      \let\SL@lrtext\SL@alternatetext
      \let\SL@eqnlrtext\SL@eqnalternatetext
    \else
      \let\SL@lrtext\SL@righttext
      \let\SL@eqnlrtext\SL@eqnrighttext
    \fi
  \or
    % 1=inner margin
    \if@twoside
      \let\SL@lrtext\SL@alternatetext
      \let\SL@eqnlrtext\SL@eqnalternatetext
    \else
      \let\SL@lrtext\SL@lefttext
      \let\SL@eqnlrtext\SL@eqnlefttext
    \fi
  \or
    % 2=left margin
    \let\SL@lrtext\SL@lefttext
    \let\SL@eqnlrtext\SL@eqnlefttext
  \or
    % 3=right margin
    \let\SL@lrtext\SL@righttext
    \let\SL@eqnlrtext\SL@eqnrighttext
  \else
    \SL@canthappen{Impossible labelposition \the\SL@labelposition}
    \SL@labelposition=3 % put everything in the right-margin for now
    \let\SL@lrtext\SL@righttext
    \let\SL@eqnlrtext\SL@eqnrighttext
  \fi
\fi
\ifx\SL@setlabel\SL@inlinetext
  \let\SL@eqnlrtext\SL@interlinetextleft
\fi
\if@showlabellabel
  \showlabels{label}
\fi
\endinput
%%
%% End of file `showlabels.sty'.
