% \iffalse      THIS IS A META-COMMENT
%<*dtx>
\ProvidesFile
%========================================================================
                       {SUBLABEL.DTX}
%========================================================================
%</dtx>
%% Copyright 1993-1999 Patrick W Daly
%% Max-Planck-Institut f\"ur Aeronomie
%% Max-Planck-Str. 2
%% D-37191 Katlenburg-Lindau
%% Germany
%% E-mail: daly@linmpi.mpg.de
% 
% This program can be redistributed and/or modified under the terms
% of the LaTeX Project Public License Distributed from CTAN
% archives in directory macros/latex/base/lppl.txt; either
% version 1 of the License, or any later version.
%
% This is a contributed file to the LaTeX2e system.
% -------------------------------------------------
%  This is a LaTeX package to permit figures, equations etc to be subnumbered
%    as 4a, 4b, 4c etc.
% Installation:
%    LaTeX this file: creates docstrip installation file sublabel.ins
%                         AND the (LaTeX2e) documentation
%    (La)TeX sublabel.ins: creates package files sublabel.sty, and optionally
%                         documentation driver sublabel.drv
%    (sublabel.ins may be edited as needed)
% Docstrip options available:
%        package - to produce a (LaTeX2e) package .sty file 
%        driver  - to produce a driver file to print the documentation
%        209     - (with package) for package that runs under LaTeX 2.09 
%        subpack - (with package) for coding included in other packages
%        agu     - (with package,subpack) for inclusion in aguplus package
%--------------------------------------------------------------------------
%<*!subpack>
%<package&209>\def\ProvidesPackage#1#2]
%<package&209>  {\typeout{Style option `#1'#2]}}
%
%  *** Identify the package file:-
%<package&!209>\NeedsTeXFormat{LaTeX2e}[1995/06/01]
%<package>\ProvidesPackage{sublabel}
%</!subpack>
%
%  *** Provide command to dislay module version
%<package&subpack>\def\ModuleVersion#1[#2]{}
%<package&subpack>    \ModuleVersion{sublabel}
%
%  *** Identify the driver file:-
%<driver>\NeedsTeXFormat{LaTeX2e}
%<driver>\ProvidesFile{sublabel.drv}
%
%  *** The DATE, VERSION, and other INFO
%\fi
%\ProvidesFile{sublabel}
       [1999/02/23 4.5 (PWD)]
% \changes{4.0}{1993 Jun  7}{Completely replacing the version based on
%                              art-jgr; made more general and flexible}
% \changes{4.1}{1993 July 20}{Initial release with {\tt docstrip}}
% \changes{4.1}{1993 Jul 20}{Discover bug; sub labels previously prefixed
%                              with `sub', but conflict with `subsection'}
% \changes{4.1}{1993 Jul 20}{\cs{stepcounter} tests if subfoo exists}
% \changes{4.2}{1993 Dec 17}{Adjust \cs{addtocounter} to step subcounter }
% \changes{4.2a}{1994 Feb 25}{Must use the old \cs{addtocounter} in
%      \cs{endeqnarray}}
% \changes{4.3}{1994 May 16}{Convert to \LaTeXe}
% \changes{4.3a}{1994 Jun 22}{Update to first official release of \LaTeXe}
% \changes{4.3b}{1995 Jan 3}{Update documentation to PWD standard}
% \changes{4.3c}{1995 Sep 18}{Fix \cs{DeclareOption} for \LaTeX\ of June 1995}
% \changes{4.3d}{1997 Mar 16}{Fix copyright for subpackage and other minor
%                                    things}
% \changes{4.4}{1997 Apr 28}{Fix so it works with other packages that change
%        \texttt{eqnarray}, like \texttt{amsmath}}
% \changes{4.5}{1999 Feb 23}{Update copyright notice}
%
% \CheckSum{209}
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \iffalse
%<*install>
%^^A =============================================
%^^A    Here is the docstrip installation file
%^^A    It is written on first LaTeX run if it 
%^^A    does not already exist
%^^A =============================================
\begin{filecontents*}{sublabel.ins}
% File: sublabel.ins
% Copyright 1999 Patrick W. Daly
%
% This file can be redistributed and/or modified under the terms
% of the LaTeX Project Public License Distributed from CTAN
% archives in directory macros/latex/base/lppl.txt; either
% version 1 of the License, or any later version.
% 
% It is an installation file for extracting package and driver
% files from the original source file. Simply process it under
% TeX or LaTeX. 

\input docstrip

\preamble
=============================================
IMPORTANT NOTICE:

This program can be redistributed and/or modified under the terms
of the LaTeX Project Public License Distributed from CTAN
archives in directory macros/latex/base/lppl.txt; either
version 1 of the License, or any later version.

This is a generated file.
It may not be distributed without the original source file \inFileName.

Full documentation can be obtained by LaTeXing that original file.
Only a few abbreviated comments remain here to describe the usage.
=============================================
\endpreamble
\postamble

<<<<< End of generated file <<<<<<
\endpostamble

\declarepreamble\driver
============================================
This is the driver file to produce the LaTeX documentation 
from the original source file \inFileName.

Make changes to it as needed. (Never change the file \inFileName!)
============================================
\endpreamble

\declarepostamble\driverq

End of documentation driver file.
\endpostamble

\keepsilent
\askforoverwritefalse

\generate{\file{sublabel.sty}{\from{sublabel.dtx}{package}}
          \file{sublabel.drv}{\usepreamble\driver\usepostamble\driverq
                           \from{sublabel.dtx}{driver}}
         }

\obeyspaces
\Msg{*******************************************}%
\Msg{* For documentation, process sublabel.dtx *}%
\Msg{*    or the driver file      sublabel.drv *}%
\Msg{*******************************************}

\endbatchfile
\end{filecontents*}
%</install>
%<*driver>
\documentclass{ltxdoc}
%<driver>%\documentclass[twoside]{ltxdoc}
%<driver>%\documentclass[a4paper]{ltxdoc}
%<driver>%\documentclass[twoside,a4paper]{ltxdoc}
\raggedbottom

 %** To include the detailed explanation of the coding, comment out
 %**   the next line
\OnlyDescription

 %** To produce a command index: add the following line for one run,
 %**   then run  makeindex -s gind.ist natbib
 %**   and reprocess, with or without this line (much faster without)
%<driver>% \EnableCrossrefs\CodelineIndex 

 %** To produce a change history: add the following line for one run,
 %**   then run  makeindex -s gglo.ist -o natbib.gls natbib.glo
 %**   and reprocess, with or without this line (faster without)
%<driver>% \RecordChanges 

\DisableCrossrefs %May stay; zapped by \EnableCrossrefs
\CodelineNumbered %May stay

\begin{document}
   \DocInput{sublabel.dtx}
\end{document}
%</driver>
%\fi
%
% \DoNotIndex{\begin,\CodelineIndex,\CodelineNumbered,\def,\DisableCrossrefs}
% \DoNotIndex{\DocInput,\documentclass,\EnableCrossrefs,\end,\GetFileInfo}
% \DoNotIndex{\NeedsTeXFormat,\OnlyDescription,\RecordChanges,\usepackage}
% \DoNotIndex{\ProvidesClass,\ProvidesPackage,\ProvidesFile,\RequirePackage}
% \DoNotIndex{\LoadClass,\PassOptionsToClass,\PassOptionsToPackage}
% \DoNotIndex{\DeclareOption,\CurrentOption,\ProcessOptions,\ExecuteOptions}
% \DoNotIndex{\AtEndOfClass,\AtEndOfPackage,\AtBeginDocument,\AtEndDocument}
% \DoNotIndex{\InputIfFileExists,\IfFileExists,\ClassError,\PackageError}
% \DoNotIndex{\ClassWarning,\PackageWarning,\ClassWarningNoLine}
% \DoNotIndex{\PackageWarningNoLine,\ClassInfo,\PackageInfo,\MessageBreak}
% \DoNotIndex{\space,\protect,\DeclareRobustCommand,\CheckCommand}
% \DoNotIndex{\newcommand,\renewcommand,\providecommand\newenvironment}
% \DoNotIndex{\renewenvironment,\newif,\newlength,\newcounter,\setlength}
% \DoNotIndex{\setcounter,\if,\ifx,\ifcase,\ifnum,\ifdim,\else,\fi}
% \DoNotIndex{\texttt,\textbf,\textrm,\textsl,\textsc}
% \DoNotIndex{\textup,\textit,\textmd,\textsf,\emph}
% \DoNotIndex{\ttfamily,\rmfamily,\sffamily,\mdseries,\bfseries,\upshape}
% \DoNotIndex{\slshape,\scshape,\itshape,\em,\LaTeX,\LaTeXe}
% \DoNotIndex{\filename,\fileversion,\filedate,\let}
% \DoNotIndex{\@@warning,\@bsphack,\@currenvir,\@eha,\@esphack,\@ifundefined}
% \DoNotIndex{\@latexerr,\@nameuse,\@tempa,\@warning,\alph,\bf,\endcsname}
% \DoNotIndex{\expandafter,\gdef,\global,\it,\newcount,\null,\relax,\thepage}
%
% \setcounter{IndexColumns}{2}
% \setlength{\IndexMin}{10cm}
% \setcounter{StandardModuleDepth}{1}
%
% \GetFileInfo{sublabel}
%
% \title{\bfseries A Package to Subnumber \LaTeX{} Counters}
%    
% \author{Patrick W. Daly}
%         
% \date{This paper describes package \texttt{\filename}\\
%       version \fileversion{} from \filedate\\[1ex]
%     \textsl{It is part of the \texttt{preprint} collection of packages}
%  }
% 
% \maketitle
%
% \pagestyle{myheadings}
% \markboth{P. W. Daly}{SUBNUMBERING FIGURES, TABLES, EQUATIONS}
% 
%^^A In order to keep all marginal notes on the one (left) side:
%^^A (otherwise they switch sides disasterously with twoside option)
% \makeatletter \@mparswitchfalse \makeatother 
%
%\begin{small}\begin{center}\textbf{Summary}\end{center}
% The stripped version of this file contains the following brief description:
%\iffalse
%<*package&!subpack>
%\fi
% \begin{verbatim}
 % To change a counter foo so that it has sublabels (4a 4b 4c ...) 
 % give the command \sublabon{foo}... \sublaboff{foo}
 % 
 % The style of the sublabel is given by command \substyle, which takes one
 % argument, a counter. It may be redefined in the document to be whatever
 % style is wanted. 
%<209> % Default is {\it\alph{#1}}, ie italic lowercase numbers.
%<*!209>
 % Default is {\itshape\alph{#1}}, ie italic lowercase numbers.
 %
 % Options for LaTeX2e:
 %   roman   the style of sublabels is small roman letter
 %   italic  the style is small italic letter (default)
%</!209>
% \end{verbatim}
%\iffalse
 %-----------------------------------------------------------
%</package&!subpack>
%\fi
%\end{small}
%
% \section{Introduction}
% The macros in this package allow all counters to be subnumbered, as for
% example 4{\itshape a}, 4{\itshape b}, 4{\itshape c}, simply by
% bracketting the objects to be so numbered with appropriate on/off
% commands. These commands specify which counters are to be subnumbered,
% and they are of global effect. This means that they will work with any
% user-defined counters too, and that their effect goes beyond any current
% environment.
% 
% \section{Invoking the Package}
% The macros in this package are included in the main document 
% with the |\usepackage| command of \LaTeXe,
% \begin{quote}
% |\documentclass[..]{...}|\\
% |\usepackage[|\emph{options}|]{|\texttt{\filename}|}|
% \end{quote}
% where the possible \emph{options} are:
% \begin{description}
% \item[\tt italic] to have subnumbers as italic lowercase letters
%       (default);
% \item[\tt roman] to have the subnumbers as Roman lowercase letters, as
%       4{\rmfamily a}.
% \end{description}
%
% Alternatively, the name of the package is added as an option to the
% |\documentstyle| command in \LaTeX~2.09 compatibility mode, as
% \begin{quote}
% |\documentstyle[..|\texttt{\filename}|..]{...}|
% \end{quote}
% In this case, no options are possible.
% 
% \section{Usage}
% \DescribeMacro{\sublabon}
% \DescribeMacro{\sublaboff}
% In order to number equations, figures, plates, and tables automatically
% with subnumbers (e.g.\ 4{\itshape a}, 4{\itshape b}, 4{\itshape c}) use
% the commands |\sublabon| and |\sublaboff|. These commands take as
% argument the name of the counter that is to be subnumbered, i.e.
% \texttt{equation}, \texttt{figure}, or \texttt{table}. The on and off
% versions bracket the objects that are to be labelled with the same number
% but different letters. For example,
% 
% \begin{quote}
% \begin{verbatim}
% \sublabon{figure}
% \begin{figure}
%   \caption{Text of Fig. 4a}
% \end{figure}
% \begin{figure}
%   \caption{Text of Fig. 4b}
% \end{figure}
% \sublaboff{figure}
% \end{verbatim}
% \end{quote}
% 
% These commands also work for the |equation| environment in the same way. 
% For the |eqnarray| environment, some care must be taken. The 
% |\sublabon| command is to be given {\em in} the first equation to be 
% bracketted, before the |\label| and |\\| commands, while the 
% |\sublaboff| command is given after the |\\| of the last equation 
% in the group. If necessary, it must come after |\end{eqnarray}|.
% \begin{quote}
% \begin{verbatim}
% \begin{eqnarray}
%   x & = & a \label{eq:x}\\%--> 1
%   \sublabon{equation}
%   y & = & b \label{eq:y}\\%--> 2a
%   z & = & c \label{eq:z}\\%--> 2b
%   \sublaboff{equation}
%   w & = & d \label{eq:w}  %--> 3
% \end{eqnarray}
% \end{verbatim}
% \end{quote}
% 
% If two groups appear adjacently, it is only necessary to give 
% |\sublabon| between them.
%
% \DescribeMacro{\substyle}
% The style in which the sublabels are written is determined by a command
% |\substyle|. Its default definition is as italic lowercase
% letters.\footnote{In \LaTeXe, if the option \texttt{roman} is added to
% the \texttt{\bslash usepackage} command, then the default is upright
% lowercase letters.} If
% one wishes, this may be changed in the document itself. It must take an
% argument that is a counter. For example, to change the style of sublabels
% to be as 5--A, 5--B, 5--C, give
% \begin{quote}
% |\renewcommand{\substyle}[1]{--\Alph{#1}}|
% \end{quote}
% \section{Interference with Other Options}
% If both |sublabel| and |figcaps| packages are to be used together, then 
% |sublabel| must be input first. This is because
% |figcaps| makes modifications so that the sublabelling also works on the page
% of figure captions.
%
% Other packages (like \texttt{amsmath}) also modify some of the commands
% redefined here. As of version~4.4, the redefinitions are delayed until 
% after all packages are loaded, so that this conflict is avoided. For
% earlier versions, things went wrong if \texttt{amsmath} were loaded after
% \texttt{filename}.
%
% \StopEventually{\PrintIndex\PrintChanges}
% 
% \section{Options with \texttt{docstrip}}
% The source \texttt{.dtx} file is meant to be processed with
% \texttt{docstrip}, for which a number of options are available:
% \begin{description}
% \item[\tt package] to produce a \texttt{.sty} package file with most
%     comments removed;
% \item[\tt 209] for a package file that will also run under the older
%     \LaTeX~2.09 and not just under the newer (mid-1994) \LaTeXe;
% \item[\tt subpack] (together with \texttt{package}) for coding that is to
%     be included inside a larger package; even more comments are removed,
%     as well as \LaTeXe{} option handling and identification;
% \item[\tt agu] (with \texttt{package,subpack}) for special coding for
%     the \textsl{AGU$^{++}$} package;
% \item[\tt driver] to produce a driver \texttt{.drv} file that will print
%     out the documentation under \LaTeXe. The documentation cannot be
%     printed under \LaTeX~2.09.
% \end{description}
% The source file \texttt{\filename.dtx} is itself a driver file and can
% be processed directly by \LaTeXe.
% 
% \section{The Coding}
% This section presents and explains the actual coding of the macros.
% It is nested between |%<*package>| and |%</package>|, which
% are indicators to \texttt{docstrip} that this coding belongs to the package 
% file.
%
% The \texttt{docstrip} option |<subpack>| should only be called if the
% coding is to be included as part of another package, in which case the 
% announcement text and \LaTeXe{} options are suppressed.
%
% An inferior version of this coding is provided for running as a 
% style file under \LaTeX~2.09. Code lines belonging to this are
% indicated with guard |<209>|; those for LaTeXe{} only with |<!209>|.
%
% There is a problem if \texttt{\filename} is used with the package
% \texttt{figcaps}, which makes modifications to the sublabelling
% commands.  Thus \texttt{\filename} must be read in \emph{before}
% \texttt{figcaps}. This is tested with the existence of the command
% |\iffigcaps|, which should not be defined at this point.
%    \begin{macrocode}
%<*package>
\@ifundefined{iffigcaps}{}
%<*!209>
  {\PackageWarningNoLine{sublabel}
     {***********************************\MessageBreak
      This package read in after `figcaps'\MessageBreak
      There could be problems with sublabelled\MessageBreak
      figure and table numbers.\MessageBreak
      ***********************************}}
%</!209>
%<*209>
 {\@@warning
  {^^J ********************************^^J
       `sublabel' read in after `figcaps'^^J
       There could be problems with sublabelled^^J
       figure and table numbers.^^J
       ********************************}}
%</209>
%    \end{macrocode}
%
% \begin{macro}{\substyle}
% \changes{4.3d}{1997 Mar 16}{Remove some superfluous lines}
% The style of the sublabel, or subnumbering, is defined by |\substyle|.  A
% default definition is provided as italic lowercase letters: 4{\itshape
% a}, 4{\itshape b}, 4{\itshape b}, etc. This command may be redefined by
% the user in the document or in a calling style.
% 
% For the \textsl{AGU$^{++}$} package, the default is upright letters.
%
%    \begin{macrocode}
\newcommand{\substyle}{}
%<*!subpack>
%<209>\def\substyle#1{\it\alph{#1}}
%    \end{macrocode}
%
% \begin{macro}{\DeclareOption}
% \changes{4.3}{1994 May 16}{Add options \texttt{roman} and \texttt{italic}.}
% \changes{4.3c}{1995 Sep 18}{Fix options \texttt{roman} and \texttt{italic}
%    for kernel changes of 1995/06/01}
% In \LaTeXe, the default depends on the option in the |\usepackage| command.
%
% Prior to \LaTeX\ of 1995/06/01, one needed |##| to specify arguments in the
% |\DeclareOption| statement, but now only a single |#| is needed.
%    \begin{macrocode}
%<*!209>
  \DeclareOption{italic}{\def\substyle#1{\itshape\alph{#1}}}
  \DeclareOption{roman}{\def\substyle#1{\alph{#1}}}
  \ExecuteOptions{italic}
  \ProcessOptions
%</!209>
%</!subpack>
%<subpack&!agu&209>\def\substyle#1{\it\alph{#1}}
%<subpack&!agu&!209>\def\substyle#1{\itshape\alph{#1}}
%<subpack&agu>\def\substyle#1{\alph{#1}}
%    \end{macrocode}
% \end{macro}\end{macro}
%
% \begin{macro}{\sublabon}
% \changes{4.3a}{1994 Jun 22}{Use \cs{newcommand}}
% The basic principle of this macro is that when |\sublabon{|\emph{ctr}|}|
% is called, then a new counter called |sb@|\emph{ctr} is created, if it
% does not already exist. That is, its internal name is |\c@sb@|\emph{ctr},
% as is standard for \LaTeX{} counters. Its value is set to $0$ and the main
% counter \emph{ctr} is incremented. The command that formats and prints
% out the value of the main counter, |\the|\emph{ctr} is redefined to be
% \begin{quote}
% |\@ldthe|\emph{ctr}|{\substyle{sb@|\emph{ctr}|}}|
% \end{quote}
% where |\@ldthe|\emph{ctr} is the stored definition |\the|\emph{ctr} and
% |\substyle| is a command that operates on a counter to format it.
%
% First |\sublabon| tests if there really is a counter with the given
% name.
%    \begin{macrocode}
\newcommand{\sublabon}[1]{\@bsphack
\@ifundefined{c@#1}{%
%<209>    \@latexerr
%<!209>    \PackageError{sublabel}
  {\protect\sublabon\space called for a non-existent counter}{\@eha}}
%    \end{macrocode}
% Now test for the subcounter |sb@|\emph{ctr} and if it does not exist,
% create it and set its value to $-1$.
%    \begin{macrocode}
 {\@ifundefined{c@sb@#1}{\expandafter\newcount\csname c@sb@#1\endcsname
  \setcounter{sb@#1}{-1}}{}%
%    \end{macrocode}
% The value $-1$ means that the subcounter has not yet been used. This
% value is set on creation, or by |\sublaboff| if the subcounter was never
% stepped. This is the trick that allows multiple calls to |\sublabon|
% without intervening |\sublaboff| calls. We have to avoid calling
% |\sublaboff| when there was no stepping. Call it only if the current
% value of the subcounter is 0 or more.
%    \begin{macrocode}
\ifnum\@nameuse{c@sb@#1}<0\else\sublaboff{#1}\fi
%    \end{macrocode}
% Set the counters \emph{ctr} and |sb@|\emph{ctr}.
%    \begin{macrocode}
\stepcounter{#1}%
\setcounter{sb@#1}{0}%
%    \end{macrocode}
% A correction must be made for the |eqnarray| environment which
% increments the |equation| counter immediately on entry and then after
% each equation. That is, the |equation| counter already holds the value of
% the \emph{next} equation. Thus we must set the two counters to the
% values that they should have for the next equation. For example, let us
% suppose the following:
% \begin{quote}
% We are outside the |eqnarray| environment, the last equation was
% number~3, so the |equation| counter has the value |3|.
% 
% We enter |eqnarray|; the |equation| counter is incremented immediately to
% |4|.
% 
% We write an equation; it obtains the number~4, and |equation| goes to
% |5|.
% 
% We call |\sublabon{equation}|, and |equation| is set to |6| and
% |sb@equation| to |0| (so far). Since the counter is stepped only 
% \emph{after} the equation in this environment, this would mean that the next
% equation would be numbered 6-0 instead of the desired 5-1. 
% 
% Hence the correction: decrement |equation| and set |sb@equation| to 1.
% \end{quote}
%    \begin{macrocode}
\def\@tempa{eqnarray}\ifx \@tempa\@currenvir 
    \addtocounter{equation}{-1}\setcounter{sb@equation}{1}\fi
%    \end{macrocode}
% Note that the above does not test if |#1| really is |equation|. However,
% if |\sublabon| is used within |eqnarray|, then it only makes sense to
% subnumber equations.
%
%  Now save the definition of |\the|\emph{ctr} as |\@ldthe|\emph{ctr}.
%  (This combination of |\expandafter| is necessary. I have experimented
%    with many other variations.)
%    \begin{macrocode}
\global\expandafter\let\csname @ldthe#1\expandafter\endcsname
    \csname the#1\endcsname
%    \end{macrocode}
% and redefine |\the|\emph{ctr} to add |\substyle| with the subcounter.
%    \begin{macrocode}
\expandafter\gdef\csname the#1\endcsname{%
   \@nameuse{@ldthe#1}{\substyle{sb@#1}}}
}\@esphack}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\sublaboff}
% \changes{4.3a}{1994 Jun 22}{Use \cs{newcommand}}
% The command that turns off the sublabelling tests if there is such a
% counter, and if there exists a subcounter for it. If both tests pass,
% then it checks that the subcounter has a non-negative value, for if it
% does not, then there was no corresponding |\sublabon| command. That is,
% the on/off commands are not nested properly. These tests are necessary to
% check for typing errors.
%    \begin{macrocode}
\newcommand{\sublaboff}[1]{\@bsphack
\@ifundefined{c@#1}{%
%<209>    \@latexerr
%<!209>    \PackageError{sublabel}
  {\protect\sublaboff\space called for a non-existent counter}{\@eha}}
 {\@ifundefined{c@sb@#1}{%
%<209>    \@warning
%<!209>    \PackageWarning{sublabel}
 {\protect\sublaboff{#1} called without any previous
%<209>    ^^J
%<!209>    \MessageBreak
  \protect\sublabon{#1} command}}
 {\ifnum\@nameuse{c@sb@#1}<0
%<209>    \@warning
%<!209>    \PackageWarning{sublabel}
 {\protect\sublaboff{#1} called without a previous
%<209>    ^^J
%<!209>    \MessageBreak
  \protect\sublabon{#1} command being active}\else
%    \end{macrocode}
% However, if the subcounter has a 0 value, then |\sublabon| was indeed
% called, but the counter was never stepped with |\stepcounter|. This is
% not an error, but it means that the old value of \emph{ctr} should be
% restored. The subcounter is set to $-1$ to indicate this to the next
% call to |\sublabon|. The numbering goes on as if |\sublabon| and 
% |\sublaboff| had never been given.
%    \begin{macrocode}
\ifnum\@nameuse{c@sb@#1}=0\addtocounter{#1}{-1}\fi
\setcounter{sb@#1}{-1}%
%    \end{macrocode}
%  Re-establish the definition of |\the|\emph{ctr} stored in
% |\@ldthe|\emph{ctr}.
%    \begin{macrocode}
\global\expandafter\let\csname the#1\expandafter\endcsname
    \csname @ldthe#1\endcsname
%    \end{macrocode}
%  Finally, if |\sublaboff| is called within the |eqnarray| environment,
% then the |equation| counter must be corrected again, to hold the number
% for the next equation.
%    \begin{macrocode}
\def\@tempa{eqnarray}\ifx \@tempa\@currenvir
    \stepcounter{equation}\fi
\fi}}\@esphack}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ref}
% \changes{4.3}{1994 May 16}{Use definition from \LaTeXe{} for NFSS with 2.09}
% \begin{macro}{\pageref}
% \changes{4.3}{1994 May 16}{Use definition from \LaTeXe{} for NFSS with 2.09}
%
% The font command within |\substyle| means that it is transferred to the
% auxiliary file in a |\newlabel| command. This causes problems under the
% New Font Selection Scheme (NFSS) when all the tokens are expanded too
% early. This problem does not exist with \LaTeX~2.09 without NFSS, nor 
% with the NFSS in \LaTeXe. To get around this, I add the revised
% definitions of |\ref| and |\pageref| from \LaTeXe, but implement them
% only for NFSS under 2.09.
%    \begin{macrocode}
%<*209>
\@ifundefined{selectfont}{}{%
\def\@setref#1#2#3{%
  \ifx#1\relax {\reset@font\bf ??}%
   \@warning{Reference `#3' on page \thepage \space undefined}%
  \else
   \expandafter#2#1\null
  \fi}
\def\ref#1{\expandafter\@setref\csname r@#1\endcsname\@firstoftwo{#1}}
\def\pageref#1{\expandafter\@setref\csname r@#1\endcsname
     \@secondoftwo{#1}}
\def\@firstoftwo#1#2{#1}
\def\@secondoftwo#1#2{#2}
}
%    \end{macrocode}
% \end{macro}\end{macro}
%
% \begin{macro}{\reset@font}
% For older implementations of \LaTeX~2.09 (before December, 1991) the
% |\reset@font| command does not exist. It is defined to be |\relax| under
% normal \LaTeX{}, but does more under NFSS. In case it is not defined, add
% it here.
%    \begin{macrocode}
\@ifundefined{reset@font}{\def\reset@font{\relax}}{}
%</209>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\stepcounter}
% \changes{4.3a}{1994 Jun 22}{Use \cs{renewcommand}}
% \changes{4.4}{1997 Apr 28}{Put into \cs{AtBeginDocument}}
% A very important matter has still to be done: redefine |\stepcounter| so
% that it increments the subcounter and not the main one. It is not
% necessary to redefine |\refstepcounter| since it calls |\stepcounter|
% itself. The existing definition of |\stepcounter| is saved and used in
% the new definition.
%
% This is done at the start of the document, not immediately, in case some
% other package is loaded that alters |\setcounter|. This also applies to 
% |\addtocounter| and |\endeqnarray|. For example, the \texttt{amsmath}
% package makes such changes, so if it is loaded after \texttt{\filename}
% it clobbers these new definitions if they are not delayed. (This used to
% happen when \textsl{AGU$^{++}$} is used with \texttt{amsmath}.)
% Do this only for \LaTeXe.
%
%    \begin{macrocode}
%<!209>\AtBeginDocument{%
\let\@ldstepcounter=\stepcounter
\renewcommand{\stepcounter}[1]
 {\@ifundefined{c@sb@#1}{\@ldstepcounter{#1}}{\ifnum
  \@nameuse{c@sb@#1}<0\relax
  \@ldstepcounter{#1}\else \@ldstepcounter{sb@#1}\fi}%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\addtocounter}
% \changes{4.2}{1993 Dec 17}{Add to allow for macros that might fiddle with
%        counters}
% \changes{4.3a}{1994 Jun 22}{Use \cs{renewcommand}}
% \changes{4.4}{1997 Apr 28}{Put into \cs{AtBeginDocument}}
% A similar refinement must be done to |\addtocounter| to allow for any
% macros that fiddle with counters. (The \texttt{planotable} environment of
% the AGU styles does this, for example.) If the fiddling is done
% explicitly (by giving |\c@|\emph{ctr} a new value) then we are lost.
% It might also be necessary to refine |\setcounter|, but at the moment I
% cannot foresee any reason for using that command where sublabels might be
% used.
%    \begin{macrocode}
\let\@ldaddtoctr=\addtocounter
\renewcommand{\addtocounter}[2]
 {\@ifundefined{c@sb@#1}{\@ldaddtoctr{#1}{#2}}{\ifnum
  \@nameuse{c@sb@#1}<0\relax
  \@ldaddtoctr{#1}{#2}\else \@ldaddtoctr{sb@#1}{#2}\fi}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endeqnarray}
% Lastly, the |eqnarray| environment itself must be altered to allow for
% the case where it is ended while |\sublabon{equation}| is
% active. (The example above was for when |\sublabon| is given within the
% environment.) The normal |\endeqnarray| command explicitly decrements the
% |equation| counter (not with |\stepcounter|) so that it now points to the
% last equation, as usual. However if the subnumbering is on at this point,
% the |equation| must be re-incremented and |sb@equation| decremented
% instead.
% \changes{4.2a}{1994 Feb 25}{Use original \cs{addtocounter}}
% \changes{4.3a}{1994 Jun 22}{Use \cs{renewcommand}}
% \changes{4.4}{1997 Apr 28}{Put into \cs{AtBeginDocument}}
%    \begin{macrocode}
\let\@ldendeqnarray=\endeqnarray
\renewcommand{\endeqnarray}{\@ldendeqnarray
  \@ifundefined{c@sb@equation}{}{\ifnum\c@sb@equation<0\else
  \@ldaddtoctr{equation}{1}\@ldaddtoctr{sb@equation}{-1}\fi}}
%<!209>}
%</package>
%    \end{macrocode}
% \end{macro}
%
% \Finale