%+
% Subeqnarray DOCUMENT-STYLE option -- Version 1.1 released 15 November 1988
%    for LaTeX version 2.09
%
% Copyright (C) 1988 by Johannes Braams, Dr Neher Laboratories
%
%    This style option defines the subeqnarray and subeqnarray*
%    environment, which behaves like the eqnarray environment,
%    except that the lines are numbered like 1a 1b 1c etc.
%    To refer to these numbers an extra label command \slabel
%    has been defined.
%
%    Many of this code was taken from LaTeX.TeX and modified for
%    this purpose.
%
% Revisions:
%
%    22 December 1988    V1.1    JB    Fixed bug in subeqnarray* environment
%
%-
\typeout{Documentstyle option `subeqnarray' V1.1;  Released 22 December 1988}
%
%    A new counter for he subequations
%    and a command to generate the number
%
\newcounter{subequation}[equation]
\def\thesubequation{\theequation\@alph\c@subequation}
%
%  \@subeqnnum: Produces the equation number for the
%     subeqnarray environment.  The following definition is for
%     flushright numbers; for flushleft numbers, see leqno.doc.
%     The {\rm ... } puts the subequation number in roman type even if
%     an subeqnarray environment appears in an italic environment.
%
\def\@subeqnnum{{\rm (\thesubequation)}}
%
%    A new label command to refer to subequations. It works
%    like the \label command and was taken from LaTeX.TeX
%
%  \slabel{FOO} then writes the following on file \@auxout :
%        \newlabel{FOO}{{eval(\@currentlabel)}{eval(\thepage)}}
%
\def\slabel#1{\@bsphack\if@filesw {\let\thepage\relax
   \xdef\@gtempa{\write\@auxout{\string
      \newlabel{#1}{{\thesubequation}{\thepage}}}}}\@gtempa
   \if@nobreak \ifvmode\nobreak\fi\fi\fi\@esphack}
%
%    Here's the subeqnarray environment,
%        it steps the equation counter,
%        sets the subequation counter equal to 1
%        and behaves much like the eqnarray environment.
%
\def\subeqnarray{\stepcounter{equation}
\let\@currentlabel=\theequation\global\c@subequation\@ne
\global\@eqnswtrue
\global\@eqcnt\z@\tabskip\@centering\let\\=\@subeqncr
$$\halign to \displaywidth\bgroup\@eqnsel\hskip\@centering
  $\displaystyle\tabskip\z@{##}$&\global\@eqcnt\@ne
  \hskip 2\arraycolsep \hfil${##}$\hfil
  &\global\@eqcnt\tw@ \hskip 2\arraycolsep $\displaystyle\tabskip\z@{##}$\hfil
   \tabskip\@centering&\llap{##}\tabskip\z@\cr}

\def\endsubeqnarray{\@@subeqncr\egroup
                     $$\global\@ignoretrue}

\def\@subeqncr{{\ifnum0=`}\fi\@ifstar{\global\@eqpen\@M
    \@ysubeqncr}{\global\@eqpen\interdisplaylinepenalty \@ysubeqncr}}

\def\@ysubeqncr{\@ifnextchar [{\@xsubeqncr}{\@xsubeqncr[\z@]}}

\def\@xsubeqncr[#1]{\ifnum0=`{\fi}\@@subeqncr
   \noalign{\penalty\@eqpen\vskip\jot\vskip #1\relax}}

\def\@@subeqncr{\let\@tempa\relax
    \ifcase\@eqcnt \def\@tempa{& & &}\or \def\@tempa{& &}
      \else \def\@tempa{&}\fi
     \@tempa \if@eqnsw\@subeqnnum\refstepcounter{subequation}\fi
     \global\@eqnswtrue\global\@eqcnt\z@\cr}

% Here's the subeqnarray* environment:

\let\@ssubeqncr=\@subeqncr
\@namedef{subeqnarray*}{\def\@subeqncr{\nonumber\@ssubeqncr}\subeqnarray}
\@namedef{endsubeqnarray*}{\global\advance\c@equation\m@ne%
                           \nonumber\endsubeqnarray}

