%%
%% This is file `mathenv.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% mathenv.dtx  (with options: `package')
%% 
%% IMPORTANT NOTICE:
%% 
%% For the copyright see the source file.
%% 
%% Any modified versions of this file must be renamed
%% with new filenames distinct from mathenv.sty.
%% 
%% For distribution of the original source see the terms
%% for copying and modification in the file mathenv.dtx.
%% 
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
%%
%% + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
%% | Copyright(C) 1997-1999 by Francesco Bosisio                 |
%% |                                                             |
%% | 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.      |
%% |                                                             |
%% | E-mail:   fbosisio@bigfoot.com                              |
%% | Web page: http://www.bigfoot.com/~fbosisio/LaTeX            |
%% | CTAN location: macros/latex/contrib/supported/bosisio/      |
%% + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
%%
%%
%%      If you make any improvment, find any bug or have
%%      any suggestion, please let me know about it.
%%
\def\FileName{mathenv}
\def\fileversion{2.2}
\def\filedate{1998/02/04}
\def\docdate{1998/02/06}
\def\filedescr{Extended math environments (BF)}
%%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{\FileName}[\filedate\space v\fileversion\space\filedescr]
%%
\newif\if@Redefine@Equation@
\DeclareOption{RedefEquation}{\@Redefine@Equation@true}
\DeclareOption{StdEquation}{\@Redefine@Equation@false}
%%
\newif\if@Redefine@Brackets@
\DeclareOption{RedefBrackets}{\@Redefine@Brackets@true}
\DeclareOption{StdBrackets}{\@Redefine@Brackets@false}
%%
\DeclareOption{Standard}{\@Redefine@Equation@false\@Redefine@Brackets@false}
%%
\ExecuteOptions{RedefEquation,RedefBrackets}
%%
\ProcessOptions*
%%
\newcommand*\StartMath@Err[1]{%
\ifmmode\PackageError{mathenv}{%
You can't use environment "#1" in math mode}{%
You probably used "\string\end{#1}" without a previous "\string\begin{#1}".}%
\else$$\fi%
}
%%
\AtBeginDocument{%
\let\@StandardEquation=\equation
}
\def\@LabelledEquation[#1]{\@StandardEquation\label{#1}}
\newenvironment{Equation}{%
\@ifnextchar[{\@LabelledEquation}{\@StandardEquation}%
}{%
\endequation%
}
\if@Redefine@Equation@
  \AtBeginDocument{\let\equation=\Equation}
\fi
%%
\def\Equation@Star[#1]{\StartMath@Err{equation*}}
\AtBeginDocument{%
\@namedef{equation*}{\@ifnextchar[{\Equation@Star}{\Equation@Star[]}}%
\@namedef{endequation*}{$$\global\@ignoretrue}%
}
%%
\let\@ArrayCR=\@arraycr
\def\@ArrayCR@quadra[#1]{\@ArrayCR[#1]\displaystyle}
\def\@ArrayCR@star@quadra[#1]{%
\@ArrayCR[#1]\displaystyle\mbox{\hspace{\SystemStarIndent}}%
}
\def\@ArrayCR@star*{%
\@ifnextchar[{\@ArrayCR@star@quadra}{%
\@ArrayCR\displaystyle\mbox{\hspace{\SystemStarIndent}}}}%
\newcommand*{\ARRAY@CR}{\@ifnextchar*{\@ArrayCR@star}{%
\@ifnextchar[{\@ArrayCR@quadra}{\@ArrayCR\displaystyle}}%
}
%%
\newcommand*\MakeAmper@Active[1]{
\global\def\@AMPERSAND{#1}%
\begingroup%
  \catcode`\~\active  \lccode`\~`\&%
  \lowercase{%
  \global\expandafter\let
     \csname ac\string\&\endcsname~%
  \gdef~{\@AMPERSAND}}%
\endgroup%
\global\catcode`\&\active%
}
%%
\newcommand*\MakeAmper@Tab{\global\catcode`\&=4}
%%
\newcommand*\OneShot@Amper[2]{%
\MakeAmper@Active{#1\expandafter\MakeAmper@Tab&#2}%
}
%%
\newlength\MultiLineIndent
\setlength{\MultiLineIndent}{1.7em}
%%
\newlength\MultiLineStarIndent
\setlength\MultiLineStarIndent{1em}
%%
\newcommand*\@MultiLineCR{%
\@ifnextchar*{\MLineCR@star}{%
\@ifnextchar[{\MLineCR@quadra}{\@ArrayCR\ML@EveryRow}}%
}
\def\MLineCR@star*{%
\@ifnextchar[{\MLineCR@star@quadra}{%
\@ArrayCR\ML@EveryRow\hspace{\MultiLineStarIndent}}%
}
\def\MLineCR@star@quadra[#1]{%
\@ArrayCR[#1]%
\ML@EveryRow%
\hspace{\MultiLineStarIndent}%
}
\def\MLineCR@quadra[#1]{\@ArrayCR[#1]\ML@EveryRow}
\newcommand*\@MultiLINEcr{%
\ifnum\catcode`\&=4%
\global\def\ML@EveryRow{&\displaystyle\mbox{}}%
\else%
\MakeAmper@Tab%
\global\def\ML@EveryRow{\displaystyle\mbox{\hspace{\MultiLineIndent}}}%
\fi%
\ML@EveryRow%
}
%%
\newcommand*{\CONTINUE}{%
\PackageError{mathenv}{%
Command "\string\CONTINUE" is obsolete: use ``\string\\*" instead}{%
You'd better correct your input file as stated above,\MessageBreak%
but if you press ENTER everything will work for the moment.}%
\MLineCR@star*%
}
%%
\newcommand*\Start@MultiLine{%
\@ifnextchar[{\Start@MultiLine@quadra}{\Start@MultiLine@no}%
}
%%
\def\Start@MultiLine@quadra[#1]{\@LABEL{#1}\Start@MultiLine@no}
%%
\newcommand*\Start@MultiLine@no{%
\OneShot@Amper{}{\displaystyle}%
\let\@arraycr=\@MultiLineCR%
\let\ML@EveryRow=\@MultiLINEcr%
\begin{array}{l@{\hspace{0.3em}}l}%
\displaystyle%
}
%%
\newcommand*\Stop@MultiLine{%
\end{array}%
\let\@arraycr=\@ArrayCR%
\MakeAmper@Tab% % For the case no "\\" is used
}
%%
\newenvironment{MultiLine}{%
\let\@LABEL=\label%
\@StandardEquation%
\Start@MultiLine%
}{%
\Stop@MultiLine%
\endequation%
\global\@ignoretrue%
}
%%
\@namedef{MultiLine*}{\ifmmode\Not@MathErr{MultiLine*}\else$$\fi%
\def\@LABEL##1{}%
\Start@MultiLine%
}
\@namedef{endMultiLine*}{\Stop@MultiLine$$\global\@ignoretrue}
%%
\newcommand*\@System@Def{%
\let\@arraycr=\ARRAY@CR%
\left\lbrace%
\begin{array}{l@{\qquad}l@{}}%
\displaystyle%
}
\def\Label@System[#1]{\@StandardEquation\label{#1}\@System@Def}
\newenvironment{System}{%
\@ifnextchar[{\Label@System}{\@StandardEquation\@System@Def}%
}{%
\end{array}%
\right.%
\endequation%
\let\@arraycr=\@ArrayCR%
\global\@ignoretrue%
}
%%
\def\System@Star[#1]{\StartMath@Err{System*}\@System@Def}
\@namedef{System*}{\@ifnextchar[{\System@Star}{\System@Star[]}}
\@namedef{endSystem*}{\end{array}\right. $$\let\@arraycr=\@ArrayCR \global\@ignoretrue}
%%
\newenvironment{EQNarray}{%
\PackageError{mathenv}{Environment "EQNarray" is obsolete}{%
Use the "equationarry" environment from the "eqnarray" package instead!}%
\eqnarray%
}{%
\endeqnarray%
}
%%
\newlength\SystemColSep
\setlength\SystemColSep{2em}
%%
\newlength\SystemBraceSep
\setlength\SystemBraceSep{3pt}
%%
\newlength\SystemStarIndent
\setlength\SystemStarIndent{2em}
%%
\newsavebox{\SysRow@Box}
\newlength\ColOne@Width
\newlength\ColTwo@Width
\newlength\SysCol@TmpWidth
%%
\newcommand*\Start@EqSysRow{%
\OneShot@Amper{%
$\end{lrbox}%
\settowidth\SysCol@TmpWidth{\usebox{\SysRow@Box}}%
\ifnum\SysCol@TmpWidth>\ColOne@Width\global\setlength\ColOne@Width\SysCol@TmpWidth\fi%
\usebox{\SysRow@Box}%
}{%
\begin{lrbox}{\SysRow@Box}$\displaystyle%
}%
\begin{lrbox}{\SysRow@Box}$\displaystyle%
}
%%
\newcommand*\Stop@EqSysRow{%
$\end{lrbox}%
\settowidth\SysCol@TmpWidth{\usebox{\SysRow@Box}}%
\ifnum\catcode`\&=4%
\ifnum\SysCol@TmpWidth>\ColTwo@Width\global\setlength\ColTwo@Width\SysCol@TmpWidth\fi%
\else%
\MakeAmper@Tab%
\ifnum\SysCol@TmpWidth>\ColOne@Width\global\setlength\ColOne@Width\SysCol@TmpWidth\fi%
\fi%
\usebox{\SysRow@Box}%
}
%%
\def\@EqSystCR@star@quadra[#1]{%
\Sys@@eqncr%
\noalign{\penalty\@eqpen\vskip #1\relax}%
\Start@EqSysRow%
\mbox{\hspace{\SystemStarIndent}}%
}
%%
\def\@EqSystCR@star*{%
\global\@eqnswfalse%
\@ifnextchar[{\@EqSystCR@star@quadra}{%
\Sys@@eqncr\Start@EqSysRow\mbox{\hspace{\SystemStarIndent}}}%
}
%%
\def\@EqSystCR@quadra[#1]{%
\Sys@@eqncr%
\noalign{\penalty\@eqpen\vskip #1\relax}%
\Start@EqSysRow%
}
%%
\newcommand*\EqSyst@CR{%
\Stop@EqSysRow%
\@ifnextchar*{\@EqSystCR@star}{%
\@ifnextchar[{\@EqSystCR@quadra}{\Sys@@eqncr\Start@EqSysRow}}%
}
%%
\let\Label@EqSystem=\relax
%%
\newcommand*\Sys@@eqncr{%
\let\reserved@a\relax%
\ifcase\@eqcnt\def\reserved@a{& &}%     %% \@eqcnt = 0
\or\def\reserved@a{&}%                  %% \@eqcnt = 1
\else%                                  %% \@eqcnt > 1
\let\reserved@a\@empty%
\PackageError{mathenv}{Too many columns in EqSystem environment}{%
You can use at most one "&" in each row of an "EqSystem" environment.}%
\fi%
\reserved@a%
\if@eqnsw\Label@EqSystem\@eqnnum\stepcounter{equation}\fi%
\global\@eqnswtrue%
\global\@eqcnt\z@%
\cr%
}
%%
\newenvironment{EqSystem}[1][\relax]{%
\setcounter{EqSys@counter}{0}%
\def\Label@EqSystem{#1}%
\def\@tempa{\relax}%
\ifx\Label@EqSystem\@tempa\else%
\def\Label@EqSystem{\stepcounter{EqSys@counter}\label{#1:\alph{EqSys@counter}}}%
\fi%
\BEGIN@EqSystem%
}{%
\Stop@EqSysRow%
%%%-------------------- \endEQNarr@y ----------------------%
\Sys@@eqncr%
\egroup%
\global\advance\c@equation\m@ne%
$$%
%%%--------------------------------------------------------%
\vspace*{-\belowdisplayskip}%
\end{minipage}%
\advance\ColTwo@Width\ColOne@Width%
\advance\ColTwo@Width\SystemColSep%
\setlength\SysCol@TmpWidth\displaywidth%
\global\advance\SysCol@TmpWidth-\ColTwo@Width%
\global\divide\SysCol@TmpWidth\tw@%
\global\advance\SysCol@TmpWidth\ColTwo@Width%
\global\advance\SysCol@TmpWidth\SystemBraceSep% %% Space around left-brace
\global\advance\SysCol@TmpWidth 1em%    %% ~= Left-brace size
\hspace{-\SysCol@TmpWidth}%
\right\lbrace%
\advance\SysCol@TmpWidth-1em%           %% ~= Left-brace size
\hspace*{\SysCol@TmpWidth}%
$$\global\@ignoretrue%
}
%%
\newcommand*\BEGIN@EqSystem{%
\setlength\ColOne@Width\z@%
\setlength\ColTwo@Width\z@%
$$\left.%
\begin{minipage}{\displaywidth}%
\vspace*{-\abovedisplayskip}%
%%%-------------------------- \EQNarr@y -------------------%
\stepcounter{equation}%
\let\@currentlabel=\theequation%
\global\@eqnswtrue%
\global\@eqcnt\z@%
\tabskip\@centering%
\let\\=\EqSyst@CR%
$$\halign to \displaywidth\bgroup%
\tabskip\z@{##}\hfil%
&\global\@eqcnt\@ne%
\hspace{\SystemColSep}{##}\hfil%
\tabskip\@centering%
&\llap{##}\tabskip\z@\cr%
%%%--------------------------------------------------------%
\Start@EqSysRow%
}
%%
\newcounter{EqSys@counter}
%%
\newcommand*\EqSystem@Star[1][\relax]{%
\stepcounter{equation}%
\setcounter{EqSys@counter}{\value{equation}}%
\def\Label@EqSystem{#1}%
\def\@tempa{\relax}%
\ifx\Label@EqSystem\@tempa\else%
\let\@currentlabel=\theequation%
\label{#1}%
\def\Label@EqSystem{\label{#1:\alph{equation}}}%
\fi%
\let\INNER@theEQUATION=\theequation%
\xdef\inner@theEQUATION{\theequation}%
\def\theequation{\inner@theEQUATION\alph{equation}}%
\setcounter{equation}{0}%
\BEGIN@EqSystem%
}
%%
\@namedef{EqSystem*}{\EqSystem@Star}
%%
\@namedef{endEqSystem*}{%
\endEqSystem%
\setcounter{equation}{\value{EqSys@counter}}%
\global\let\theequation=\INNER@theEQUATION%
}
\if@Redefine@Brackets@
  \AtBeginDocument{%
    \let\math=\(
    \let\endmath=\)
    \let\displaymath=\[
    \let\enddisplaymath=\]
    \renewcommand*{\(}{\left(}%
    \renewcommand*{\)}{\right)}%
    \renewcommand*{\[}{\left[}%
    \renewcommand*{\]}{\right]}%
    \renewcommand*{\{}{\left\lbrace}%
    \renewcommand*{\}}{\right\rbrace}%
  }
\fi
\endinput
%%
%% End of file `mathenv.sty'.
