%%
%% 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 1999, 2001-09, 2013-22, Norman Gray
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public Licence, either version 1.3c
%% of this licence or (at your option) any later version.
%% The latest version of this licence is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3c 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 <https://nxg.me.uk>
%%
%% This work consists of the files showlabels.dtx and showlabels.ins,
%% and the derived file showlabels.sty.

%%%% File: showlabels.dtx
%%%% Source: dc6d682fadbc, 2022-07-18T23:32:32+01:00

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{showlabels}[2022/07/18\space v1.9.2]
\typeout{Package: `showlabels' v1.9.2\space<2022/07/18>}
\newif\ifSL@AMS
\@ifundefined{maketag@@@}
  \SL@AMSfalse
  {\SL@AMStrue\typeout{with amsmath equation tags}}
\def\SL@eqntext{%
  \ifSL@labelsinline
    \let\@tempa\SL@interlinetextleft
  \else
    \let\@tempa\SL@eqnlrtext
  \fi
  \@tempa
}
\def\SL@wrap@labeller#1{%
  \expandafter\let\csname SL@orig@#1\expandafter\endcsname\csname #1\endcsname
  \expandafter\def\csname #1\endcsname{%
    \csname SL@orig@#1\endcsname
    \ifx\SL@labelname\relax
      % do nothing
    \else
      \SL@eqntext{\SL@labelname}%
    \fi
    \global\let\SL@labelname\relax}}
\ifSL@AMS
  \def\SL@setlabel@ams{%
    \ifx\df@label\@empty
      \ifx\SL@labelname\relax
        % do nothing
      \else
        \SL@eqntext{\SL@labelname}%
      \fi
    \else
      \SL@eqntext{\df@label}%
    \fi
    \global\let\SL@labelname\relax
  }
  \let\SL@orig@maketag@@@=\maketag@@@
  \def\SL@maketag@@@#1{%
    \SL@orig@maketag@@@{#1}%
    \SL@setlabel@ams
  }
  \let\SL@orig@tagform@\tagform@
  \def\SL@tagform@#1{%
    \SL@orig@tagform@{#1}%
    \SL@setlabel@ams
  }
\else
  %% \let\SL@eqnnum=\@eqnnum
  %% \def\@eqnnum{%
  %%   \SL@eqnnum
  %%   \ifx\SL@labelname\relax
  %%     % do nothing
  %%   \else
  %%     \SL@eqntext{\SL@labelname}%
  %%   \fi
  %%   \global\let\SL@labelname\relax
  %% }
  \SL@wrap@labeller{@eqnnum}
\fi
\global\let\SL@labelname\relax
\@ifundefined{ttfamily}
  {\providecommand{\showlabelfont}{\small\tt}}
  {\providecommand{\showlabelfont}{\small\ttfamily}}
\providecommand{\showlabelsetlabel}[1]{{\normalfont\showlabelfont\SL@fmt@{#1}}}
\def\SL@gobblethree#1#2#3{}
\def\SL@prlabelname#1{%
\expandafter\expandafter\expandafter\SL@gobblethree
    \expandafter\string\csname r@#1\endcsname}
\def\showlabels{\@ifnextchar[\showlabels@{\showlabels@[]}}
\def\showlabels@[#1]#2{%
  \@temptokena=\expandafter{\csname #2\endcsname}
  \def\@tempa{#1}%
  \ifx\@tempa\@empty
    \expandafter\let\csname SL@fmt@#2\endcsname\relax
  \else
    \expandafter\def\csname SL@fmt@#2\endcsname{#1}%
  \fi
  \expandafter\edef\csname SL@init@#2\endcsname{%
    \let\csname SL@orig#2\endcsname\the\@temptokena
    \let\the\@temptokena\csname SL@#2\endcsname}
  \AtBeginDocument{\csname SL@init@#2\endcsname}%
  \expandafter\def\csname SL@#2\endcsname{%
    \expandafter\let\expandafter\SL@fmt@\csname SL@fmt@#2\endcsname
    \SL@showlabels{#2}}
}
\let\SL@fmt@\relax
\DeclareRobustCommand\SL@showlabels[1]{%
  \@bsphack
  \expandafter\let\expandafter\SL@orig@@next\csname SL@orig#1\endcsname
  \def\showlabeltype{#1}%
  \begingroup
  \@ifstar
    {\@sanitize\SL@showlabelsplainstar}
    {\@ifnextchar[
       {\SL@showlabelsopt}
       {\@sanitize\SL@showlabelsplain}}}
\def\SL@showlabelsopt[#1]{% #1 is read before \@sanitize
  \@sanitize
  \SL@showlabelsopt@ii{#1}}
\def\SL@showlabelsopt@ii#1#2{%
  \endgroup
  \SL@setlabel{#2}\relax
  \ifhmode \spacefactor\@savsf \ifdim\@savsk>\z@ \hskip1sp \fi\fi
  \SL@orig@@next[#1]{#2}}
\def\SL@showlabelsplain#1{%
  \endgroup
  \SL@setlabel{#1}\relax
  \ifhmode \spacefactor\@savsf \ifdim\@savsk>\z@ \hskip1sp \fi\fi
  \SL@orig@@next{#1}}
\def\SL@showlabelsplainstar#1{%
  \endgroup
  \SL@setlabel{#1}\relax
  \ifhmode \spacefactor\@savsf \ifdim\@savsk>\z@ \hskip1sp \fi\fi
  \SL@orig@@next*{#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\ifdim\displaywidth>0pt
    \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\fi
}
\def\SL@inlinetext#1{%
  \SL@interlinetextright{\SL@prlabelname{#1}}%
}
\def\SL@interlinetextleft{\SL@setlefttrue\SL@interlinetext}
\def\SL@interlinetextright{\SL@setleftfalse\SL@interlinetext}
\def\SL@interlinetext#1{%
  \setbox\@tempboxa=\hbox{\showlabelsetlabel{\SL@prlabelname{#1}}}\dp\@tempboxa\z@
  \ifvmode
    \@tempdima=\prevdepth
    \nointerlineskip\vbox to 0pt{\vss
      \hbox to \hsize{\hss \box\@tempboxa}}\nobreak
    \prevdepth=\@tempdima
  \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}
\newif\ifSL@labelsinline
\SL@labelsinlinefalse
\DeclareOption{marginal}{\SL@labelsinlinefalse}
\DeclareOption{inline}{\SL@labelsinlinetrue}
\def\SL@setlabel{%
  \ifSL@labelsinline
    \let\@tempa\SL@inlinetext
  \else
    \let\@tempa\SL@margtext
  \fi
  \@tempa
}
\def\showlabelsinline{\SL@labelsinlinetrue}
\def\showlabelsmarginal{\SL@labelsinlinefalse}
\newif\ifSL@labellabel
\SL@labellabeltrue
\DeclareOption{nolabel}{\SL@labellabelfalse}
\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
\ifSL@labellabel
  \showlabels{label}
  \ifSL@AMS
    \ifx\showlabels\@gobble
      % do nothing -- we're in [final] mode (see test case t13)
    \else
      \AtBeginDocument{%
        \let\maketag@@@\SL@maketag@@@
        \let\tagform@\SL@tagform@}
    \fi
  \fi
  \@ifundefined{theIEEEsubequationdis}\relax % and \theequationdis
    {\SL@wrap@labeller{theIEEEsubequationdis}
     \SL@wrap@labeller{theequationdis}}
\fi
\endinput
%%
%% End of file `showlabels.sty'.
