%*CMZ :  2.00/00 04/08/94  13.04.27  by  L. Felawka
%*-- Author :
%$% subfigure.sty
%$% Subfigure command for use with the LaTeX figure environment.
%$% $Header: /usr2/cvsroot/chaossim/doc/subfigure.sty,v 1.2 1998/10/06 00:14:43 felawka Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% @LaTeX-style-file{
%%%    Author              = "Steven Douglas Cochran",
%%%    Version             = "1.5",
%%%    Date                = "11 August 1992",
%%%    Time                = "23:13:12 EDT",
%%%    Filename            = "subfigure.sty",
%%%    Address             = "Digital Mapping Laboratory
%%%                           School of Computer Science
%%%                           Carnegie-Mellon University
%%%                           5000 Forbes Avenue
%%%                           Pittsburgh, PA 15213-3890
%%%                           USA",
%%%    Telephone           = "(412) 268-5654",
%%%    FAX                 = "",
%%%    checksum            = "52839 173 895 8006",
%%%    Email               = "sdc+@CS.CMU.EDU (Internet)",
%%%    CodeTable           = "ISO/ASCII",
%%%    Keywords            = "LaTeX, floats",
%%%    Archives            = "shsu*",
%%%    Supported           = "yes",
%%%    Abstract            = "LaTeX document-style option for
%%%                           providing support for the inclusion of
%%%                           small `sub' figures.  It simplifies the
%%%                           positioning, captioning and labeling of
%%%                           of them within a single figure
%%%                           environment.",
%%%    DocString           = "The checksum field above contains a CRC-16
%%%                           checksum as the first value, followed by
%%%                           the equivalent of the standard UNIX wc
%%%                           (word count) utility output of lines,
%%%                           words, and characters.  This is produced
%%%                           by Robert Solovay's checksum utility.",
%%% }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% $Log: subfigure.sty,v $
%%% Revision 1.2  1998/10/06 00:14:43  felawka
%%% Release of OSF/DU version of CHAOSSIM 2.00/00
%%%
%%% Revision 1.1.1.1  1998/10/05 22:06:58  felawka
%%% Import of OSF/DU version of CHAOSSIM 2.00/00 in CMZ format
%%%
%$%  Revision 1.5  92/08/11  23:13:12  sdc
%$%  Fixed a bug which caused an problem with captions that contained
%$%  expressions like \sqrt;  This was pointed out by Tom Scavo
%$%  (scavo@cie.uoregon.edu).  A separate bug was fixed which caused
%$%  different sized captions to be misaligned;  This problem was
%$%  pointed out by Simon Marshall (S.Marshal@Hull.ac.uk).  Also
%$%  cleaned up the code a mite and *changed* the figure spacing so that
%$%  if no optional section is given, then the figure is only followed
%$%  by \subfigbottomskip and not that plus (\subfigcapskip + \strut
%$%  height).  This should make it easier to adjust spacing as desired.
%$%
%$%  Revision 1.4  92/06/27  10:40:34  sdc
%$%  Added a hack to allow the \label command to be used within the
%$%  body of the subfigure giving a reference label in the form
%$%  \arabic{thefigure}\thesubfigure.  Added standard file header for
%$%  style.
%$%
%$%  Revision 1.3  90/10/22  17:04:28  cochran
%$%  Changed test for empty caption inside of \@subfigure to compare
%$%  tokens and not the caption vs. \@empty.  The former (incorrect)
%$%  test caused an error when the first two letters of the caption
%$%  were the same.
%$%
%$%  Revision 1.2  89/08/30  07:18:29  cochran
%$%  Added a separate bottom margin and expanded the comments.
%$%
%$%  Revision 1.1  88/11/02  11:03:46  cochran
%$%  Initial revision.
%$%
%$%  05 Mar 86  cochran@dworkin.usc.edu (USC-IRIS)
%$%  Created.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%$% Usage:  \documentstyle[...,subfigure,...]{...}
%$%
%$%             \subfigure[CAPTIONtext]{FIGUREbox}
%%%
%%% Creates a subfigure box with an optional CAPTION under a FIGURE.
%%% The FIGURE is centered with \subfigtopskip of vertical space added
%%% above.  If there is a CAPTION, then \subfigcapskip vertical space
%%% is added below the FIGURE followed by the CAPTION.  Finally,
%%% \subfigbottomskip of vertical space added at the bottom.
%%%
%%% If a CAPTION is given (including a null CAPTION `[]') then the
%%% subfigure is labeled with a counter formatted by the macro
%%% `\thesubfigure' which returns `(a)', `(b)', etc.  If desired,
%%% this macro may be redefined.  The counter used for labeling the
%%% subfigures is `subfigure' and is incremented for each subfigure
%%% regardless of whether a CAPTION was printed.
%%%
%%% One example of use is to surround the figure in a tabular
%%% environment (this preserves alignment along the bottom of the
%%% figures when the figures and/or the captions are different
%%% heights):
%%%
%%% \def\goodgap{%                   	     *---------*
%%%   \hspace{\subfigtopskip}%               |  ..   . |   *---------*
%%%   \hspace{\subfigbottomskip}}            |  .   .  |   | . .  .  |
%%%                                          | .. . .  |   | .  . .. |
%%%  \begin{figure}                          *---------*   *---------*
%%%    \centering                             (a) First     (b) Second
%%%    \begin{tabular[t]{c}                                 Figure
%%%      \subfigure[First]{...}\goodgap
%%%      \subfigure[Second Figure]{...}\\          *---------*
%%%      \subfigure[Third]{\label{3figs-c}...}%    | . .. .  |
%%%    \end{tabular}                               | . .. .  |
%%%    \caption{Three Subfigures}                  *---------*
%%%    \label{3figs}                                (c) Third
%%%  \end{figure}                           Figure 1: Three Subfigures
%%%
%%%  Figure~\ref{3figs} contains         Figure 1 contains two top `sub-
%%%  two top `subfigures' and            figures' and Figure 1(c).
%%%  Figure~\ref{3figs-c}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%
%%  Setup constants and variables
%%
\newcounter{subfigure}[figure] % Subfigure counter.
\newcount\@subfigtemp

\def\thesubfigure{(\alph{subfigure})}   % Generate CAPTION preface.
\def\p@subfigure{\number\@subfigtemp}   % Figure number for \label.

\def\subcapsize{\footnotesize} % Size of the CAPTION font.
\def\subfigtopskip{10pt}       % Length from the top of the subfigure
                               %   box to the begining of the FIGURE box.
\def\subfigbottomskip{10pt}    % Length from the bottom of the CAPTION to
                               %   the bottom of the subfigure.
\def\subfigcapskip{10pt}       % Length from the bottom of the FIGURE box
                               %   to the begining of the CAPTION.
\def\subfigcapmargin{10pt}     % Indentation of the caption from the
                               %   sides of the subfigure box (This
                               %   should always be positive).

%%
%% Define the subfigure command
%%
\def\subfigure{%
  \@subfigtemp=\value{figure}%   Since the figure caption is usually
  \advance\@subfigtemp\@ne %       generated later, we must anticipate
  \refstepcounter{subfigure}%      the future value of its counter.
  \leavevmode
  \@ifnextchar [%
    {\@subfigure}%
    {\@subfigure[\@empty]}}

\long\def\@subfigure[#1]#2{%
  \setbox\@tempboxa \hbox{#2}%
  \@tempdima=\wd\@tempboxa
  \vtop{%
    %% Put the figure in the top box
    \vbox{%
      \vskip\subfigtopskip
      \box\@tempboxa}%
    %% Now skip down and add the caption paragraph
    %%   (unless #1 == \@empty)
    \ifx \@empty#1\relax \else
      \vskip\subfigcapskip
      \setbox\@tempboxa \hbox{\subcapsize\thesubfigure\space #1}%
      \@tempdimb=-\subfigcapmargin
      \multiply\@tempdimb\tw@
      \advance\@tempdimb\@tempdima
      \hbox to\@tempdima{%
        \hfil
        \ifdim \wd\@tempboxa >\@tempdimb
          %% Comment too long for one line
          \parbox[t]{\@tempdimb}{\subcapsize\thesubfigure\space #1}%
        \else
          \box\@tempboxa
        \fi
        \hfil}%
    \fi
    %% Finally add the bottom spacing.
    \vskip\subfigbottomskip}}
