%%
%% This is file `mathenv.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% mdwtab.dtx  (with options: `mathenv')
%% 
%% IMPORTANT NOTICE
%%
%% mdwtab package -- another rewrite of the tabular environment, etc.
%% Copyright (c) 1996 Mark Wooding
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; if not, write to the Free Software
%% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mathenv}
                [1998/04/28 1.9 Various maths environments]
%% \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         \~}
%%
%%
\newif\if@fleqn
\newif\if@leqno
\DeclareOption{fleqn}{\@fleqntrue}
\DeclareOption{leqno}{\@leqnotrue}
\ProcessOptions
\RequirePackage{mdwtab}
\newif\if@eqalast
\newskip\eqaopenskip
\newskip\eqacloseskip
\newskip\eqacolskip
\newskip\eqainskip
\newskip\splitleft
\newskip\splitright
\AtBeginDocument{%
  \eqacloseskip\@centering%
  \eqacolskip1.5em\@plus\@m\p@
  \eqainskip\z@%
  \if@fleqn%
    \eqaopenskip\mathindent%
    \splitleft\mathindent\relax%
    \splitright\mathindent\@minus\mathindent\relax%
  \else%
    \eqaopenskip\@centering%
    \splitleft2.5em\@minus2.5em%
    \splitright\splitleft%
  \fi%
  \relax%
}
\def\dsp@startouter{%
  \let\dsp@end\dsp@endouter%
  $$%
}
\def\dsp@endouter{$$}
\def\dsp@startinner{%
  \let\dsp@end\dsp@endinner%
  \if@fleqn\kern-\mathindent\fi%
  \if@leqno\vtop\else\vtop\fi\bgroup%
}
\def\dsp@endinner{\egroup}
\def\dsp@start{%
  \ifmmode%
    \ifinner\mth@err@mdsp\fi%
    \expandafter\dsp@startinner%
  \else%
    \ifhmode\ifinner\mth@err@hdsp\fi\fi%
    \expandafter\dsp@startouter%
  \fi%
}
\def\dsp@tabpause{%
  \def\tab@startpause%
    {\penalty\postdisplaypenalty\vskip\belowdisplayskip}%
  \def\tab@endpause%
    {\penalty\predisplaypenalty\vskip\abovedisplayskip}%
}
\let\eqastyle\displaystyle
\def\eqnarray{%
  \eqnarray@i\eqa@eqcount%
}
\@namedef{eqnarray*}{\eqnarray@i{}}
\def\eqnarray@i#1{\@ifnextchar[{\eqnarray@ii{#1}}{\eqnarray@ii{#1}[rcl]}}
\def\eqnarray@ii#1[#2]{%
  \stepcounter{equation}%
  \def\@currentlabel{\p@equation\theequation}%
  \let\eqa@oldnumber\eqa@number%
  \def\eqa@defnumber{#1}%
  \global\let\eqa@number\eqa@defnumber%
  \@eqalastfalse%
  \m@th%
  \colset{eqnarray}%
  \tab@initread%
  \def\tab@tabtext{&\tabskip\z@skip}%
  \tab@preamble{\tabskip\z@skip}%
  \tab@readpreamble{#2@{\tabskip\eqacloseskip}}%
  \dsp@tabpause%
  \col@sep.5\eqainskip%
  \everycr{}%
  \let\\\@eqncr%
  \dsp@start%
  \tabskip\eqaopenskip%
  \halign to\displaywidth\expandafter\bgroup%
    \the\tab@preamble%
    &&\eqa@lastcol\hb@xt@\z@{\hss##}\tabskip\z@\cr%
}
\def\endeqnarray{%
  \eqa@eqnum%
  \egroup%
  \dsp@end%
  \global\let\eqa@number\eqa@oldnumber%
  \global\@ignoretrue%
  \global\advance\c@equation\m@ne%
}
\expandafter\let\csname endeqnarray*\endcsname\endeqnarray
\colpush{eqnarray}
\coldef r{\tabcoltype{\hfil$\eqastyle}{{}$}}
\coldef c{\tabcoltype{\hfil$\eqastyle{}}{{}$\hfil}}
\coldef l{\tabcoltype{$\eqastyle{}}{$\hfil}}
\coldef x{\tabcoltype{\if@fleqn\else\hfil\fi$\eqastyle}{$\hfil}}
\collet T [tabular]T
\coldef L{\tabcoltype{\hb@xt@2em\bgroup$\eqastyle}{$\hss\egroup}}
\coldef :{\tabspctype{\tabskip\eqacolskip}}
\coldef q{\tabspctype{\quad}}
\collet > [tabular]>
\collet < [tabular]<
\collet * [tabular]*
\collet @ [tabular]@
\colpop
\def\@eqncr{\tab@cr\eqacr@i\interdisplaylinepenalty\@M}%
\def\eqacr@i#1#2{%
  \eqa@eqnum%
  \noalign{\penalty#2\vskip\jot\vskip#1}%
}
\if@leqno
  \def\eqa@eqpos#1{%
    \hb@xt@.01\p@{}\rlap{\normalfont\normalcolor\hskip-\displaywidth#1}%
  }
\else
  \def\eqa@eqpos#1{\normalfont\normalcolor#1}
\fi
\def\eqa@eqnum{%
  \global\let\eqa@lastcol\@eqalasttrue%
  \eqa@eqnum@i%
}
\def\eqa@eqnum@i{%
  \relax%
  \if@eqalast%
    \expandafter\eqa@eqnum@ii%
  \else%
    \expandafter\eqa@eqnum@iii%
  \fi%
}
\def\eqa@eqnum@ii{%
  \eqa@eqpos\eqa@number%
  \global\let\eqa@number\eqa@defnumber%
  \global\let\eqa@lastcol\eqa@@lastcol%
  \cr%
}
\def\eqa@eqnum@iii{&\eqa@eqnum@i}
\def\eqa@@lastcol{\mth@err@number\setbox\z@}
\let\eqa@lastcol\eqa@@lastcol
\newcommand\eqnumber[1][\eqa@eqcount]{\gdef\eqa@number{#1}}
\def\eqa@eqcount{(\theequation)\global\advance\c@equation\@ne}
\def\nonumber{\global\let\eqa@number\@empty}
\def\eqnalign{\@ifnextchar[\eqnalign@i{\eqnalign@i[rcl]}}
\def\eqnalign@i[#1]{%
  \@ifnextchar[{\eqnalign@ii{#1}}{\eqnalign@ii{#1}[c]}%
}
\def\eqnalign@ii#1[#2]{%
  \let\\\eqn@cr%
  \colset{eqnarray}%
  \tab@initread%
  \def\tab@tabtext{&\tabskip\z@skip}%
  \tabskip\z@skip%
  \col@sep.5\eqainskip%
  \tab@readpreamble{#1}%
  \everycr{}%
  \if#2t\vtop\else%
    \if#2b\vbox\else%
      \vcenter%
    \fi%
  \fi%
  \bgroup%
  \halign\expandafter\bgroup\the\tab@preamble\cr%
}
\def\endeqnalign{%
  \crcr%
  \egroup%
  \egroup%
}
\def\eqn@cr{\tab@cr\eqn@cr@i{}{}}
\def\eqn@cr@i#1{\cr\noalign{\vskip\jot\vskip#1}\@gobble}
\def\eqlines{\eqnarray[x]}
\let\endeqlines\endeqnarray
\expandafter\edef\csname eqlines*\endcsname{%
  \expandafter\noexpand\csname eqnarray*\endcsname[x]%
}
\expandafter\let\csname endeqlines*\expandafter\endcsname
                \csname endeqnarray*\endcsname
\def\spliteqn{%
  \let\eqa@oldnumber\eqa@number%
  \global\let\eqa@number\eqa@eqcount%
  \spliteqn@i%
}
\@namedef{spliteqn*}{%
  \let\eqa@oldnumber\eqa@number%
  \gdef\eqa@number{}%
  \spliteqn@i%
}
\def\endspliteqn{%
  \hfilneg\seq@lastcr%
  \egroup%
  \dsp@end%
  \global\let\eqa@number\eqa@oldnumber%
  \global\advance\c@equation\m@ne%
}
\expandafter\let\csname endspliteqn*\endcsname\endspliteqn
\def\spliteqn@i{%
  \stepcounter{equation}%
  \def\@currentlabel{\p@equation\theequation}%
  \if@leqno%
    \global\let\seq@docr\seq@eqnocr%
  \else%
    \global\let\seq@docr\seq@cr%
  \fi%
  \global\let\seq@lastcr\seq@eqnocr%
  \dsp@start%
  \dsp@tabpause%
  \def\\{\seq@docr}%
  \seq@dosplit%
    {\hb@xt@\displaywidth{%
      \hskip\splitleft\hfil$\displaystyle##$%
      \hfil\hskip\splitright}}%
    {\hfilneg}%
}
\def\subsplit{%
  \let\\\seq@cr%
  \vcenter\bgroup%
  \seq@dosplit{\hfil\qquad$##$\qquad\hfil}{\hfilneg\hskip-2em}%
}
\def\endsubsplit{%
  \hfilneg\hskip-2em\cr%
  \egroup\egroup%
}
\def\seq@dosplit#1#2{%
  \halign\bgroup%
    #1&&\mth@err@number\setbox\z@\hbox{##}\cr%
  #2\relax%
}
\def\seq@eqnocr{%
  &\omit%
  \hb@xt@\z@{\hss\eqa@eqpos\eqa@number}%
  \global\let\seq@docr\seq@cr%
  \global\let\seq@lastcr\seq@cr%
  \seq@cr%
}
\def\seq@cr{\tab@cr\seq@cr@i\interdisplaylinepenalty\@M}
\def\seq@cr@i#1#2{\cr\noalign{\penalty#2\vskip\jot\vskip#1}}
\def\genmatrix#1#2#3#4#5{%
  \let\mat@style#1%
  \ifx#2\scriptstyle%
    \let\mat@font\scriptfont%
  \else\ifx#2\scriptscriptstyle%
    \let\mat@font\scriptscriptfont%
  \else%
    \let\mat@font\textfont%
  \fi\fi%
  \ifx\mat@style\scriptstyle%
    \let\mat@textsize\scriptsize%
  \else\ifx\mat@style\scriptscriptstyle%
    \let\mat@textsize\scriptscriptsize%
  \else%
    \let\mat@textsize\relax%
  \fi\fi%
  \def\mat@left{\bgroup\mat@style\left#4#3\vcenter\bgroup}%
  \toks@{\egroup#3\right#5\egroup}%
  \@tempswatrue%
  \ifx\mat@style\displaystyle\else\ifx\mat@style\textstyle\else%
    \@tempswafalse%
    \setbox\z@\hbox\bgroup$%
    \toks@\expandafter{\the\toks@$\m@th\egroup\raise.75\p@\box\z@}%
  \fi\fi%
  \if@tempswa\ifmmode\else%
    $\m@th%
    \toks@\expandafter{\the\toks@$}%
  \fi\fi%
  \edef\mat@right{\the\toks@}%
  \@ifnextchar[\genmatrix@i{\genmatrix@i[[c]}%
}
\def\genmatrix@i[#1]{%
  \colset{matrix}%
  \tab@initread%
  \setbox\z@\hbox{$\mat@style\mskip12mu$}%
  \edef\tab@tabtext{&\kern\the\wd\z@}%
  \tab@readpreamble{#1}%
  \if1\ifx\mat@style\scriptstyle1\else%
      \ifx\mat@style\scriptscriptstyle1\else0\fi\fi%
    \baselineskip\fontdimen10\mat@font\tw@%
    \advance\baselineskip\fontdimen12\mat@font\tw@%
    \lineskip\thr@@\fontdimen8\mat@font\thr@@%
  \else%
    \baselineskip\fontdimen8\mat@font\tw@%
    \advance\baselineskip\fontdimen11\mat@font\tw@%
    \lineskip7\fontdimen8\mat@font\thr@@%
  \fi%
  \lineskiplimit\lineskip%
  \let\\\mat@cr%
  \tabskip\z@skip%
  \col@sep\z@%
  \mat@left%
  \halign\expandafter\bgroup\the\tab@preamble\tabskip\z@skip\cr%
  \ifx\mat@font\textfont%
    \omit$\mat@style\mathstrut$\cr\noalign{\kern-\baselineskip}%
  \fi%
}
\def\endgenmatrix{%
  \crcr%
  \ifx\mat@font\textfont%
    \omit$\mat@style\mathstrut$\cr\noalign{\kern-\baselineskip}%
  \fi%
  \egroup%
  \mat@right%
}
\def\mat@cr{\tab@cr\mat@cr@i{}{}}
\def\mat@cr@i#1{\cr\noalign{\vskip#1}\@gobble}
\def\newmatrix#1#2{%
  \@namedef{#1}{\genmatrix#2}%
  \expandafter\let\csname end#1\endcsname\endgenmatrix%
}
\newmatrix{matrix}{{\textstyle}{\textstyle}{\,}{.}{.}}
\newmatrix{pmatrix}{{\textstyle}{\textstyle}{\,}{(}{)}}
\newmatrix{dmatrix}{{\textstyle}{\textstyle}{\,}}
\newmatrix{smatrix}{{\scriptstyle}{\scriptstyle}{}{.}{.}}
\newmatrix{spmatrix}{{\scriptstyle}{\scriptstyle}{}{(}{)}}
\newmatrix{sdmatrix}{{\scriptstyle}{\scriptstyle}{}}
\newmatrix{smatrix*}{{\scriptstyle}{\textstyle}{}{.}{.}}
\newmatrix{spmatrix*}{{\scriptstyle}{\textstyle}{}{(}{)}}
\newmatrix{sdmatrix*}{{\scriptstyle}{\textstyle}{}}
\def\script{%
  \let\mat@style\scriptstyle%
  \def\mat@left{\vcenter\bgroup}%
  \def\mat@right{\egroup}%
  \let\mat@font\scriptfont%
  \let\mat@textsize\scriptsize%
  \@ifnextchar[\genmatrix@i{\genmatrix@i[c]}%
}
\let\endscript\endgenmatrix
\colpush{matrix}
\coldef l{\tabcoltype{\kern\z@$\mat@style}{\m@th$\hfil}}
\coldef c{\tabcoltype{\hfil$\mat@style}{\m@th$\hfil}}
\coldef r{\tabcoltype{\hfil$\mat@style}{\m@th$}}
\coldef T#1{\tab@aligncol{#1}{\begingroup\mat@textsize}{\endgroup}}
\coldef {[}{%
  \@firstoftwo{%
    \ifnum\tab@columns=\z@%
      \def\@tempa##1\q@delim{%
        \tab@mkpreamble##1[##1\q@delim%
      }%
      \expandafter\@tempa%
    \else%
      \tab@setstate\tab@prestate%
      \tab@append\tab@preamble{&}%
      \expandafter\tab@mkpreamble%
    \fi%
  }%
}
\colpop
\def\mdw@dots#1{\ensuremath{\mathpalette\mdw@dots@i{#1}}}
\def\mdw@dots@i#1#2{%
  \setbox\z@\hbox{$#1\mskip1.8mu$}%
  \dimen@\wd\z@%
  \setbox\z@\hbox{$#1.$}%
  #2%
}
\def\vdots{%
  \mdw@dots{\vbox{%
    \baselineskip4\dimen@%
    \lineskiplimit\z@%
    \kern6\dimen@%
    \copy\z@\copy\z@\box\z@%
  }}%
}
\def\ddots{%
  \mdw@dots{\mathinner{%
    \mkern1mu%
    \raise7\dimen@\vbox{\kern7\dimen@\copy\z@}%
    \mkern2mu%
    \raise4\dimen@\copy\z@%
    \mkern2mu%
    \raise\dimen@\box\z@%
    \mkern1mu%
  }}%
}
\def\cases{\left\{\,\array{@{}lTl@{}}}
\def\endcases{\endarray\,\right.}
\def\smcases{\left\{\smarray{@{}lTl@{}}}
\def\endsmcases{\endsmarray\,\right.}
\def\mth@error{\PackageError{mathenv}}
\def\mth@err@number{%
  \mth@error{Too many `&' characters found}{%
    You've put too many `&' characters in an alignment^^J%
    environment (like `eqnarray' or `spliteqn') and wandered^^J%
    into trouble.  I've gobbled the contents of that column^^J%
    and hopefully I can recover fairly easily.%
  }%
}
\def\mth@err@mdsp{%
  \mth@error{Can't do displays in nondisplay maths mode}{%
    You're trying to start a display environment, but you're^^J%
    in nondisplay maths mode.  The display will appear but^^J%
    don't blame me when it looks horrible.%
  }%
}
\def\mth@err@hdsp{%
  \mth@error{Can't do displays in LR mode}{%
    You're trying to start a display environment, but you're^^J%
    in LR (restricted horizontal) mode.  Everything will go^^J%
    totally wrong, so your best bet is to type `X', fix the^^J%
    mistake and start again.%
  }%
}
\endinput
%%
%% End of file `mathenv.sty'.
