% \iffalse meta comment
% File: subfloat.dtx Copyright (C) 1999 Harald Harders
% \fi
%
% \iffalse
%
%<*package>
\def\packagename{subfloat}
\def\fileversion{2.12}
\def\filedate{2002/10/30}
\def\docdate{2002/10/30}
%</package>
%<*driver>
\documentclass{ltxdoc}
\IfFileExists{subfloat.sty}{\usepackage{subfloat}
 \let\subfloatSTYfound\active}{\GenericWarning{subfloat.dtx}{Package
 file subfloat.sty not found (Documentation will be messed up!^^J^^A
 Generate subfloat.sty by (La)TeXing subfloat.ins, process
 subfloat.dtx again)^^J}\stop}
\usepackage{longtable}
\title{The \texttt{subfloat} package\thanks{This file has version 
    \fileversion\ last revised \filedate, documentation dated \docdate.}}
\author{Harald Harders\\\texttt{h.harders@tu-bs.de}}
\date{File Date \filedate, Printed \today}
\newlength{\tempdima}%
\makeatletter
\renewenvironment{table}[1][]{%
  \@float{table}[#1]%
  \centering%
  \setlength{\tempdima}{\abovecaptionskip}%
  \setlength{\abovecaptionskip}{\belowcaptionskip}%
  \setlength{\belowcaptionskip}{\tempdima}%
  }{%
\end@float
}
\makeatother
\EnableCrossrefs
\CodelineIndex
\DoNotIndex{\def,\edef,\let,\newcommand,\newenvironment,\newcounter}
\DoNotIndex{\setcounter,\space,\endinput,\@auxout,\@bsphack,\@esphack}
\DoNotIndex{\@firstoftwo,\if,\else,\fi,\ifnum,\fi,\ifx,\fi,\MessageBreak}
\DoNotIndex{\relax,\string,\thepage,\@ifpackageloaded,\expandafter}
\DoNotIndex{\message,\newif,\protect,\protected@write}
\CodelineNumbered
\RecordChanges
\CheckSum{281}
\setcounter{topnumber}{5}
\setcounter{bottomnumber}{1}
\setcounter{totalnumber}{6}
\begin{document}
 \DocInput{subfloat.dtx}
\end{document}
%</driver>
% \fi
%
% \changes{1.01}{1999/06/08}{Documentation improved}
% \changes{1.02}{1999/06/08}{Error in change history corrected}
% \changes{1.03}{1999/10/08}{email address changed}
% \changes{1.04}{2002/08/18}{Suggestions made by Frank Mittelbach 
%   implemented: Changes in implementation, macros to change label format}
% \changes{2.00}{2002/09/06}{Total new implementation of the package
%   with help of Frank Mittelbach}
% \changes{2.12}{2002/10/30}{Correct a typo (thanks to Michael M\"uller)}%
% \maketitle
% \begin{abstract}
% \noindent This package enables subnumbering of floats (figures and
% tables) similar to the subequations environment of the amsmath
% package. It does not the same as the subfigure package which
% generates subfigures within one normal figure.
% \end{abstract}
%
% \tableofcontents
%
% \section*{Copyright}
% Copyright  1999, 2002 Harald Harders.
%
% 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.
%
% \section{Introduction}
% Sometimes two or more floats (figures or tables) belong together in a
% way you should not use different caption numbers for them. 
% With a subnumbering like that of the amsmath package for equations
% it is possible to point out the connection of the floats.
% This package provides two environments and four macros to achive
% subnumbering of floats.
% It is possible to change the caption labels.
%
% In case of problems or bugs please send an email to my address
% printed on the title page.
%
% \section{The user interface}
%
% To use this package place
% \begin{verbatim}
% \usepackage{subfloat}
% \end{verbatim}
% in the preamble of your document.
% No options are necessary.
%
% \changes{2.10}{2002/09/06}{Add counting of subfloats}%
% If you want to be able to count the number of subfloats with the
% same main number you have to add the package option |countmax|:
% \begin{verbatim}
% \usepackage[countmax]{subfloat}
% \end{verbatim}
% For more description to counting see section~\ref{sec:count}.
%
% \subsection{Environments}
% \DescribeEnv{subfigures}
% Put
% \begin{verbatim}
% \begin{subfigures}
% \end{subfigures}
% \end{verbatim}
% around the figures which belong together.
% By default, they get the same figure number with an increasing
% lowercase character added. 
% \DescribeEnv{subtables}
% In the same way you can put
% \begin{verbatim}
% \begin{subtables}
% \end{subtables}
% \end{verbatim}
% around tables. The macros for the environments have to be placed outside
% the picture or table environments.
%
% \subsection{Macros}
% \DescribeMacro{\subfiguresbegin}
% \DescribeMacro{\subfiguresend}
% Instead using of the environments it is possible to use adequate macros:
% \begin{verbatim}
% \subfiguresbegin
% \subfiguresend
% \end{verbatim}
% \DescribeMacro{\subtablesbegin}
% \DescribeMacro{\subtablesend}
% or
% \begin{verbatim}
% \subtablesbegin
% \subtablesend
% \end{verbatim}
%
% Put these macros in place of the environment macros. The macros are
% necessary to be able to nest subnumbered figures and tables.
%
% If you put labels inside the figure and table environments the subfloat
% label numberes are referenced. 
% If you want a reference to the common figure or table number place a 
% label right after the |\begin{subfigures}|, |\subfiguresbegin|, 
% |\begin{subtables}|, or |\subtablesbegin| command.
% 
% \section{Examples}
% \subsection{Using the environments}
%
% \DescribeEnv{subfigures}
% The code
% \begin{verbatim}
% \begin{subfigures}
% \label{fig:fig1a2}
% %
% \begin{figure}\centering
%   \fbox{fig. 1}
%   \caption{This is the first figure}\label{fig:fig1}
% \end{figure}
% %
% \begin{figure}\centering
%   \fbox{fig. 2}
%   \caption{This is the second figure}\label{fig:fig2}
% \end{figure}
% %
% \end{subfigures}
% \end{verbatim}
% produces the output of the figures~\ref{fig:fig1a2} 
% (figure~\ref{fig:fig1} and figure~\ref{fig:fig2}).
% References are made as usual with
% e.\,g. |\ref{fig:fig1}|.
% %
% \begin{subfigures}
% \label{fig:fig1a2}
% %
% \begin{figure}\centering
%   \fbox{fig. 1}
%   \caption{This is the first figure}\label{fig:fig1}
% \end{figure}
% %
% \begin{figure}\centering
%   \fbox{fig. 2}
%   \caption{This is the second figure}\label{fig:fig2}
% \end{figure}
% %
% \end{subfigures}
%
% \DescribeEnv{subtables}
% The output of the tables~\ref{tab:tab1} and \ref{tab:tab1} is
% generated similarly:
% \begin{verbatim}
% \begin{subtables}
% %
% \begin{table}\centering
%   \caption{This is the first table}\label{tab:tab1}
%   \begin{tabular}{l} \hline
%   table 1\\ \hline
%   \end{tabular}
% \end{table}
% %
% \begin{table}\centering
%   \caption{This is the second table}\label{tab:tab2}
%   \begin{tabular}{l} \hline
%   table 2\\ \hline
%   \end{tabular}
% \end{table}
% %
% \end{subtables}
% \end{verbatim}
% %
% \begin{subtables}
% %
% \begin{table}\centering
%   \caption{This is the first table}\label{tab:tab1}
%   \begin{tabular}{l} \hline
%   table 1\\ \hline
%   \end{tabular}
% \end{table}
% %
% \begin{table}\centering
%   \caption{This is the second table}\label{tab:tab2}
%   \begin{tabular}{l} \hline
%   table 2\\ \hline
%   \end{tabular}
% \end{table}
% %
% \end{subtables}
%
% The environment names |subfigures| and |subtables| were
% chosen to be similar to the |subequations| environment of the
% amsmath package. But what is to do when both environments have to be
% nested? This case is handled in the next section.
% 
% \subsection{Using the macros}
% \DescribeMacro{\subfiguresbegin}
% \DescribeMacro{\subfiguresend}
% \DescribeMacro{\subtablesbegin}
% \DescribeMacro{\subtablesend}
% The usage of the macros is shown in the example below:
% \begin{verbatim}
% \subfiguresbegin
% \begin{figure}
% [...]
% \begin{table}
% [...]
% \subtablesbegin
% \begin{table}
% [...]
% \begin{figure}
% [...]
% \subfiguresend
% \begin{figure}
% [...]
% \begin{table}
% [...]
% \subtablesend
% \end{verbatim}
% %
% \subfiguresbegin
% %
% \begin{figure}\centering
%   \fbox{fig. 3}
%   \caption{This is the third figure}\label{fig:fig3}
% \end{figure}
% %
% \begin{table}\centering
%   \caption{This is the third table}\label{tab:tab3}
%   \begin{tabular}{l} \hline
%   table 3\\ \hline
%   \end{tabular}
% \end{table}
%
% \subtablesbegin
% %
% \begin{table}\centering
%   \caption{This is the forth table}\label{tab:tab4}
%   \begin{tabular}{l} \hline
%   table 4\\ \hline
%   \end{tabular}
% \end{table}
% %
% \begin{figure}\centering
%   \fbox{fig. 4}
%   \caption{This is the forth figure}\label{fig:fig4}
% \end{figure}
% %
% \subfiguresend
% %
% \begin{figure}\centering
%   \fbox{fig. 5}
%   \caption{This is the fifth figure}\label{fig:fig5}
% \end{figure}
% %
% \begin{table}\centering
%   \caption{This is the fifth table}\label{tab:tab5}
%   \begin{tabular}{l} \hline
%   table 5\\ \hline
%   \end{tabular}
% \end{table}
% %
% \subtablesend
% 
% With these macros it is possible to realise nested subnumbers of
% figures and tables. Even nested subnumbers of figures or tables and
% equations made with the subequations environment of the amsmath
% package are possible.
% 
% \section{Change the label format}
%
% The standard label format is the global float number followed by a
% lowercase alphanumerical subfloat number.
% This can be changed by redefining the commands |\thesubfloatfigure|
% and |\thesubfloattable|.
% Both define the whole float number including the main number. 
% The main number is referred by |\themainfigure| resp.\
% |\themaintable|. 
% The counters of the subfloats are |subfloatfigure| resp.\
% |subfloattable|.
% The default values are:
% \begin{verbatim}
% \newcommand*\thesubfloatfigure{\themainfigure\alph{subfloatfigure}}
% \newcommand*\thesubfloattable{\themaintable\alph{subfloattable}}
% \end{verbatim}
% If you want to print the subnumber of figures in brackets, you may
% define this:
% \begin{verbatim}
% \renewcommand*\thesubfloatfigure{\themainfigure(\alph{subfloatfigure})}
% \end{verbatim}
% If you want a sublabel in the format 1--1, 1--2, \dots\ you can
% get it by the following command sequence:
% \begin{verbatim}
% \renewcommand*\thesubfloatfigure{\themainfigure--\arabic{subfloatfigure}}
% \end{verbatim}
%
% Since it is done the same for tables this it not described again.
%
% \section{Count subfloats}%
% \label{sec:count}%
% \changes{2.10}{2002/09/06}{Add counting of subfloats}%
%
% If the package option |countmax| is used the package counts the
% number of all subfloats with the same main float number. This number
% is stored in the counters |subfloatfiguremax| resp.\
% |subfloattablemax| and can be used for changeing the labels, e.g.:
% \begin{verbatim}
% \renewcommand*\thesubfloatfigure{%
%     \themainfigure(\arabic{subfloatfigure}/\arabic{subfloatfiguremax})}
% \end{verbatim}
% If the package option is not set but |subfloatfiguremax| used the
% package generates an error message.
% In order to get the numbers right \LaTeX\ has to be run twice or
% three times.\footnote{Internally, this is implemented using labels.
%   After the first \LaTeX\ run, the counter is zero end thus not
%   displayed for alpha or roman numbering.}
%
% \section{Command reference}
% This sections gives a short list of the main commands and environments 
% of this package.
%
% \begin{longtable}[l]{@{}p{0.3\linewidth}@{}p{0.7\linewidth}@{}}
% \hline
% \textbf{environment}&\textbf{description}\\
% \hline
% \texttt{subfigures}&Increases the figure number by one and starts
% subnumbering by appending a, b, c, \dots to the fixed figure number\\
% \texttt{subtables}&Increases the table number by one and starts
% subnumbering by appending a, b, c, \dots to the fixed table number\\
% \hline
% \end{longtable}
% \begin{longtable}[l]{@{}p{0.3\linewidth}@{}p{0.7\linewidth}@{}}
% \hline
% \textbf{macro}&\textbf{description}\\
% \hline
% \texttt{\bslash subfiguresbegin}&Increases the figure number by one
% and starts subnumbering by appending a, b, c, \dots to the fixed figure
% number\\
% \texttt{\bslash subfiguresend}&Returns to ordinary figure numbering\\
% \texttt{\bslash subtablesbegin}&Increases the table number by one and starts
% subnumbering by appending a, b, c, \dots to the fixed table number\\
% \texttt{\bslash subtablesend}&Returns to ordinary table numbering\\
% \hline
% \texttt{\bslash thesubfloatfigure}& Defines the output format of the
% main and subfigure number.\\
% \texttt{\bslash themainfigure}& Number of the main figure\\
% \texttt{\bslash thesubfloattable}& Defines the output format of the
% main and subtable number.\\
% \texttt{\bslash themaintable}& Number of the main table\\
% \hline
% \end{longtable}
%
%
% \section*{To do}
%
% The macros |\subfiguresbegin|, |\subfiguresend|, |\subtablesbegin|,
% and |\subtablesend| should test whether they are inside or outside a
% subfloat area and generate an errormessage if they are used where
% they can't.
%
% \section*{Acknowledgements}
% 
% Thanks to Frank Mittelbach who had the idea to make the label
% changeable. Furthermore, he helped to develop a user friendly
% interface to do this.
%
% \StopEventually{\PrintChanges \PrintIndex}
%
% \section{The implementation}
% \iffalse
%<*package>
% \fi
% Heading of the package:
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{subfloat}
         [\filedate\space version \fileversion]
\message{Package `subfloat', Version \fileversion\space of \filedate.}
%    \end{macrocode}
%
% \subsection{Options}%
% \changes{2.10}{2002/09/06}{Add counting of subfloats}%
%
%    \begin{macrocode}
\newif\ifsubfloat@countmax
%    \end{macrocode}
%    \begin{macrocode}
\DeclareOption{countmax}{\subfloat@countmaxtrue}
\DeclareOption{nocountmax}{\subfloat@countmaxfalse}
%    \end{macrocode}
%    \begin{macrocode}
\ExecuteOptions{nocountmax}
%    \end{macrocode}
%    \begin{macrocode}
\ProcessOptions\relax
%    \end{macrocode}
%
% \subsection{Figures}
%
% \begin{macro}{\thesubfloatfigure}%
% Defining the output format of captions:
%    \begin{macrocode}
\newcommand*\thesubfloatfigure{\themainfigure\alph{subfloatfigure}}
%    \end{macrocode}
% \end{macro}
%
% \begin{environment}{subfigures}%
% Defining the environment |subfigures|:
%    \begin{macrocode}
\newenvironment{subfigures}{%
%    \end{macrocode}
% Call start command for subnumbering:
%    \begin{macrocode}
  \subfiguresbegin
}{%
%    \end{macrocode}
% Call end command for subnumbering:
%    \begin{macrocode}
  \subfiguresend
  \global\@ignoretrue
}
%    \end{macrocode}
% \end{environment}
%
% Make a copy of |\c@figure| in |\c@subfloatfigure| in order to be
% able to use the counter |subfloatfigure| in the defintion of 
% |\thesubfloatfigure|:
%    \begin{macrocode}
\let\c@subfloatfigure=\c@figure
%    \end{macrocode}
% Define the boolean |\ifinsubfloatfigures| to determine if we are
% inside a subfloatfigures area:
% \changes{2.11}{2002/09/10}{Test for nesting of subfloatfigure areas}%
%    \begin{macrocode}
\newif\ifinsubfloatfigures
%    \end{macrocode}
% \begin{macro}{\thefiguresbegin}%
% Defining the macro |\thefiguresbegin|:
%    \begin{macrocode}
\newcommand{\subfiguresbegin}{%
%    \end{macrocode}
% Check if |\subfiguresbegin| may be called here:
% \changes{2.11}{2002/09/10}{Test for nesting of subfloatfigure areas}%
%    \begin{macrocode}
\ifinsubfloatfigures
  \PackageError{subfloat}{Cannot start subfloatfigures inside
    a\MessageBreak subfloatfigure area}{You probably have used
    \string\subfiguresbegin\space or \string\begin{subfigures} inside
      the^^Jsame environment or after \string\subfiguresbegin.}%
\fi
%    \end{macrocode}
% Set testing boolean to true:
% \changes{2.11}{2002/09/10}{Test for nesting of subfloatfigure areas}%
%    \begin{macrocode}
\global\insubfloatfigurestrue
%    \end{macrocode}
% Increase figure number:
%    \begin{macrocode}
  \refstepcounter{figure}%
%    \end{macrocode}
% Save value of counter |figure|:
%    \begin{macrocode}
  \protected@xdef\figure@value{\the\c@figure}%
%    \end{macrocode}
% Save counter |figure| in printed format:
%    \begin{macrocode}
  \protected@xdef\themainfigure{\thefigure}%
%    \end{macrocode}
% Save the original macro |\thefigure|:
%    \begin{macrocode}
  \global\let\thefigure@original=\thefigure
%    \end{macrocode}
% Reset counter |figure| to zero.
% It functions as subfloat counter until |\subfiguresend|.
%    \begin{macrocode}
  \setcounter{figure}{0}%
%    \end{macrocode}
% Redefine macro |\thefigure| to use subnumbering:
%    \begin{macrocode}
  \gdef\thefigure{\thesubfloatfigure}%
%    \end{macrocode}
% Set counter to maximal number of subfloatfigures. Therefore local
% redefinition of |\@setref| in order to change the warning and to set
% the counter |subfloatfiguresmax| correct. Thereafter call |\@setref|
% using the |\ref| command:
% \changes{2.10}{2002/09/06}{Add counting of subfloats}%
%    \begin{macrocode}
  \ifsubfloat@countmax
    {\def\@setref##1##2##3{%
      \ifx##1\relax
        \protect\G@refundefinedtrue
        \setcounter{subfloatfiguremax}{0}%
        \PackageWarningNoLine{subfloat}{Reference `##3' on page
          \thepage \space undefined\MessageBreak
          (count subfloatfigures)}%
      \else
        \setcounter{subfloatfiguremax}{\expandafter\@firstoftwo##1}%
      \fi}%
    \ref{subfloat@@figure\figure@value}}%
  \fi
%    \end{macrocode}
% Redefine the macro |\p@subfigure| (from |subfigure.sty|) in order to
% generate correct labels for subfigures:
% \changes{2.01}{2002/09/06}{Add support for subfigure.sty}%
%    \begin{macrocode}
%%  \@ifpackageloaded{subfigure}{%
    \let\p@subfigure=\thesubfloatfigure
%%  }{}%
%    \end{macrocode}
% Ignore spaces:
%    \begin{macrocode}
  \ignorespaces
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\thefiguresend}
% Defining the macro |\thefiguresend|:
%    \begin{macrocode}
\newcommand{\subfiguresend}{%
%    \end{macrocode}
% Check if |\subfiguresend| may be called here:
% \changes{2.11}{2002/09/10}{Test for nesting of subfloatfigure areas}%
%    \begin{macrocode}
\ifinsubfloatfigures
\else
  \PackageError{subfloat}{Cannot stop subfloatfigures outside
    a\MessageBreak subfloatfigure area}{You probably have used
    \string\subfiguresend\space or \string\end{subfigures} without
      starting a^^Jsubfloatfigure area using the same environment or
      \string\subfiguresbegin.}%
\fi
%    \end{macrocode}
% Set testing boolean to false:
% \changes{2.11}{2002/09/10}{Test for nesting of subfloatfigure areas}%
%    \begin{macrocode}
\global\insubfloatfiguresfalse
%    \end{macrocode}
% Write the number of subfloatfigures into the |aux| file:
% \changes{2.10}{2002/09/06}{Add counting of subfloats}%
%    \begin{macrocode}
  \ifsubfloat@countmax
    \subfloat@figurelabel{subfloat@@figure\figure@value}%
  \fi
%    \end{macrocode}
% Set counter |figure| back to original value:
%    \begin{macrocode}
  \setcounter{figure}{\figure@value}%
%    \end{macrocode}
% Restore the original macro |\thefigure|:
%    \begin{macrocode}
  \global\let\thefigure=\thefigure@original
%    \end{macrocode}
% Restore the original macro |\p@subfigure| (from |subfigure.sty|):
% \changes{2.01}{2002/09/06}{Add support for subfigure.sty}%
%    \begin{macrocode}
%%  \@ifpackageloaded{subfigure}{%
    \let\p@subfigure=\thefigure
%%  }{}%
%    \end{macrocode}
% Ignore spaces:
%    \begin{macrocode}
  \ignorespaces
}
%%
%    \end{macrocode}
% \end{macro}
%
% Introduce the counter for the number of subfloatfigures. If both the
% option |countmax| is not used and this counter is used, generate an
% error message:
% \changes{2.10}{2002/09/06}{Add counting of subfloats}%
%    \begin{macrocode}
\ifsubfloat@countmax
  \newcounter{subfloatfiguremax}
\else
  \newcounter{subfloatfiguremax}
  \let\orig@c@subfloatfiguremax=\c@subfloatfiguremax
  \def\c@subfloatfiguremax{\orig@c@subfloatfiguremax
    \PackageError{subfloat}{Counter subfloatfiguremax used
      without\MessageBreak
      package option countmax}{The counter subfloatfiguremax may
      only be used with the package option\MessageBreak
      countmax. Normally this error happens when
      \string\thesubfloatfigure\space is redefined.}} 
\fi
%    \end{macrocode}
% \begin{macro}{\subfloat@figurelabel}
% This command makes a label for the current figure, always with an
% arabic number:
% \changes{2.10}{2002/09/06}{Add counting of subfloats}%
%    \begin{macrocode}
\ifsubfloat@countmax
  \newcommand*\subfloat@figurelabel[1]{\@bsphack
    \protected@write\@auxout{}%
           {\string\newlabel{#1}{{\the\c@figure}{\thepage}}}%
    \@esphack}
\fi
%    \end{macrocode}
% \end{macro}
%
% \subsection{Tables}
%
% \begin{macro}{\thesubfloattable}%
% Defining the output format of captions:
%    \begin{macrocode}
\newcommand*\thesubfloattable{\themaintable\alph{subfloattable}}
%    \end{macrocode}
% \end{macro}
%
% \begin{environment}{subtables}%
% Defining the environment |subtables|:
%    \begin{macrocode}
\newenvironment{subtables}{%
%    \end{macrocode}
% Call start command for subnumbering:
%    \begin{macrocode}
  \subtablesbegin
}{%
%    \end{macrocode}
% Call end command for subnumbering:
%    \begin{macrocode}
  \subtablesend
  \global\@ignoretrue
}
%    \end{macrocode}
% \end{environment}
%
% Make a copy of |\c@table| in |\c@subfloattable| in order to be
% able to use the counter |subfloattable| in the defintion of 
% |\thesubfloattable|:
%    \begin{macrocode}
\let\c@subfloattable=\c@table
%    \end{macrocode}
% Define the boolean |\ifinsubfloattables| to determine if we are
% inside a subfloattables area:
% \changes{2.11}{2002/09/10}{Test for nesting of subfloattable areas}%
%    \begin{macrocode}
\newif\ifinsubfloattables
%    \end{macrocode}
% \begin{macro}{\thetablesbegin}%
% Defining the macro |\thetablesbegin|:
%    \begin{macrocode}
\newcommand{\subtablesbegin}{%
%    \end{macrocode}
% Check if |\subtablesbegin| may be called here:
% \changes{2.11}{2002/09/10}{Test for nesting of subfloattable areas}%
%    \begin{macrocode}
\ifinsubfloattables
  \PackageError{subfloat}{Cannot start subfloattables inside
    a\MessageBreak subfloatfigure area}{You probably have used
    \string\subtablesbegin\space or \string\begin{subtables} inside
      the^^Jsame environment or after \string\subtablesbegin.}%
\fi
%    \end{macrocode}
% Set testing boolean to true:
% \changes{2.11}{2002/09/10}{Test for nesting of subfloattable areas}%
%    \begin{macrocode}
\global\insubfloattablestrue
%    \end{macrocode}
% Increase table number:
%    \begin{macrocode}
  \refstepcounter{table}%
%    \end{macrocode}
% Save value of counter |table|:
%    \begin{macrocode}
  \protected@xdef\table@value{\the\c@table}%
%    \end{macrocode}
% Save counter |table| in printed format:
%    \begin{macrocode}
  \protected@xdef\themaintable{\thetable}%
%    \end{macrocode}
% Save the original macro |\thetable|:
%    \begin{macrocode}
  \global\let\thetable@original=\thetable
%    \end{macrocode}
% Reset counter |table| to zero. It functions as subfloat counter
% until |\subtablesend|.
%    \begin{macrocode}
  \setcounter{table}{0}%
%    \end{macrocode}
% Redefine macro |\thetable| to use subnumbering:
%    \begin{macrocode}
  \gdef\thetable{\thesubfloattable}%
%    \end{macrocode}
% Set counter to maximal number of subfloattables. Therefore local
% redefinition of |\@setref| in order to change the warning and to set
% the counter |subfloattablesmax| correct. Thereafter call |\@setref|
% using the |\ref| command:
% \changes{2.10}{2002/09/06}{Add counting of subfloats}%
%    \begin{macrocode}
  \ifsubfloat@countmax
    {\def\@setref##1##2##3{%
      \ifx##1\relax
        \protect\G@refundefinedtrue
        \setcounter{subfloattablemax}{0}%
        \PackageWarningNoLine{subfloat}{Reference `##3' on page
          \thepage \space undefined\MessageBreak
          (count subfloattables)}%
      \else
        \setcounter{subfloattablemax}{\expandafter\@firstoftwo##1}%
      \fi}%
    \ref{subfloat@@table\table@value}}%
  \fi
%    \end{macrocode}
% Redefine the macro |\p@subtable| (from |subfigure.sty|) in order to
% generate correct labels for subtables:
% \changes{2.01}{2002/09/06}{Add support for subfigure.sty}%
%    \begin{macrocode}
%%  \@ifpackageloaded{subfigure}{%
    \let\p@subtable=\thesubfloattable
%%  }{}%
%    \end{macrocode}
% Ignore spaces:
%    \begin{macrocode}
  \ignorespaces
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\subtablesend}
% \changes{2.12}{2002/10/30}{Remove the corrupt greater sign}%
% Defining the macro |\thetablesend|:
%    \begin{macrocode}
\newcommand{\subtablesend}{%
%    \end{macrocode}
% Check if |\subtablesend| may be called here:
% \changes{2.11}{2002/09/10}{Test for nesting of subfloatfigure areas}%
%    \begin{macrocode}
\ifinsubfloattables
\else
  \PackageError{subfloat}{Cannot stop subfloattables outside
    a\MessageBreak subfloatfigure area}{You probably have used
    \string\subtablesend\space or \string\end{subtables} without
      starting a^^Jsubfloatfigure area using the same environment or
      \string\subtablesbegin.}%
\fi
%    \end{macrocode}
% Set testing boolean to false:
% \changes{2.11}{2002/09/10}{Test for nesting of subfloatfigure areas}%
%    \begin{macrocode}
\global\insubfloattablesfalse
%    \end{macrocode}
% Write the number of subfloattables into the |aux| file:
% \changes{2.10}{2002/09/06}{Add counting of subfloats}%
%    \begin{macrocode}
  \ifsubfloat@countmax
    \subfloat@tablelabel{subfloat@@table\table@value}%
  \fi
%    \end{macrocode}
% Set counter |table| back to original value:
%    \begin{macrocode}
  \setcounter{table}{\table@value}%
%    \end{macrocode}
% Restore the original macro |\thetable|:
%    \begin{macrocode}
  \global\let\thetable=\thetable@original
%    \end{macrocode}
% Restore the original macro |\p@subtable| (from |subfigure.sty|):
% \changes{2.01}{2002/09/06}{Add support for subfigure.sty}%
%    \begin{macrocode}
%%  \@ifpackageloaded{subfigure}{%
    \let\p@subtable=\thetable
%%  }{}%
%    \end{macrocode}
% Ignore spaces:
%    \begin{macrocode}
  \ignorespaces
}
%%
%    \end{macrocode}
% \end{macro}
%
% Introduce the counter for the number of subfloattables. If both the
% option |countmax| is not used and this counter is used, generate an
% error message:
% \changes{2.10}{2002/09/06}{Add counting of subfloats}%
%    \begin{macrocode}
\ifsubfloat@countmax
  \newcounter{subfloattablemax}
\else
  \newcounter{subfloattablemax}
  \let\orig@c@subfloattablemax=\c@subfloattablemax
  \def\c@subfloattablemax{\orig@c@subfloattablemax
    \PackageError{subfloat}{Counter subfloattablemax used
      without\MessageBreak
      package option countmax}{The counter subfloattablemax may
      only be used with the package option\MessageBreak
      countmax. Normally this error happens when
      \string\thesubfloattable\space is redefined.}} 
\fi
%    \end{macrocode}
% \begin{macro}{\subfloat@tablelabel}
% This command makes a label for the current table, always with an
% arabic number:
% \changes{2.10}{2002/09/06}{Add counting of subfloats}%
%    \begin{macrocode}
\ifsubfloat@countmax
  \newcommand*\subfloat@tablelabel[1]{\@bsphack
    \protected@write\@auxout{}%
           {\string\newlabel{#1}{{\the\c@table}{\thepage}}}%
    \@esphack}
\fi
%    \end{macrocode}
% \end{macro}
%
% The end of the package:
%    \begin{macrocode}
\endinput
%    \end{macrocode}
% \iffalse
%</package>
% \fi
% \Finale

