%%
%% 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
%%
%%%% Copyright 2005--2013, Norman Gray
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is Norman Gray <http://nxg.me.uk>
%%
%% This work consists of the files showlabels.dtx and showlabels.ins,
%% and the derived file showlabels.cls.
\def\filename{showlabels}
\def\fileversion{1.6.6}
\def\filedate{2013/12/06}
\def\docdate{2013 December 6}
\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}%
    %\message{maketag@@@: df@label=\df@label, SL@labelname=\SL@labelname, env=\@currenvir}%
    \ifx\df@label\@empty
      \ifx\SL@labelname\relax
        % do nothing
      \else
        \SL@eqnlrtext{\SL@labelname}%
      \fi
    \else
      \SL@eqnlrtext{\df@label}%
    \fi
    \global\let\SL@labelname\relax
  }
\else
  \let\SL@eqnnum=\@eqnnum
  \def\@eqnnum{%
    \SL@eqnnum
    \ifx\SL@labelname\relax
      % do nothing
    \else
      \SL@eqnlrtext{\SL@labelname}%
    \fi
    \global\let\SL@labelname\relax
  }
\fi
\global\let\SL@labelname\relax
\@ifundefined{ttfamily}
  {\providecommand{\showlabelfont}{\small\tt}}
  {\providecommand{\showlabelfont}{\small\ttfamily}}
\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}}
}
\DeclareRobustCommand\SL@showlabels[1]{%
  \def\@tempa{\csname SL@orig#1\endcsname}%
  \@ifnextchar[\SL@showlabelsopt\SL@showlabelsplain
}
\def\SL@showlabelsopt[#1]#2{%
  \@bsphack
  \SL@setlabel{#2}\relax
  \ifhmode \spacefactor\@savsf \ifdim\@savsk>\z@ \hskip1sp \fi\fi
  \@tempa[#1]{#2}%
}
\def\SL@showlabelsplain#1{%
  \@bsphack
  \SL@setlabel{#1}\relax
  \ifhmode \spacefactor\@savsf \ifdim\@savsk>\z@ \hskip1sp \fi\fi
  \@tempa{#1}%
}
\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
    \xdef\SL@labelname{\SL@prlabelname{#1}}%
  \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{\SL@prlabelname{#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}%
    \showlabelrefline
  }}%
    \else
      \hbox to 0pt{%
  \vbox to 0pt{\vss
    \box\@tempboxa
    \showlabelrefline
  }\hss}%
    \fi
    \penalty10000
  \fi
}
\def\showlabelrefline{\hrule width 0.05em height 1.5ex depth 0pt }
\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'.
