%%% ====================================================================
%%%  @LaTeX-style-file{
%%%     author          = "Enrico Bertolazzi",
%%%     version         = "0.1",
%%%     date            = "15-MAY-96",
%%%     filename        = "easymat.sty",
%%%     address         = "Laboratorio di Matematica Applicata
%%%                        Trento University,
%%%                        Via Mesiano, Trento, Italy",
%%%     FAX             = "+39 (461) 882672",
%%%     email           = "bertolaz@ing.unitn.it (Internet)",
%%%     supported       = "yes. Please send comments via E-mail",
%%%     docstring       = "package for easy typing equations.
%%%
%%% INSTALLATION:
%%%   Put this file where your TeX looks for inputs.
%%%
%%% DOCUMENTATION:
%%%  Compile docmat.tex.
%%%
%%% COPYING:
%%%   Copying of part or all of this file is allowed under the following
%%%   conditions only:
%%%   (1) You may freely distribute unchanged copies of the file. Please
%%%       include the documentation when you do so.
%%%   (2) You may modify a renamed copy of the file, but only for personal
%%%       use or use within an organization.
%%%   (3) You may copy fragments from the file, for personal use or for
%%%       distribution, as long as credit is given where credit is due.
%%%
%%%   You are NOT ALLOWED to take money for the distribution or use of
%%%   this file or modified versions or fragments thereof, except for
%%%   a nominal charge for copying etc.
%%%
%%%  }
%%% ====================================================================
\typeout{Document Style `easymat'  version 0.1 <15-MAY-1996>.}
%% BEGIN easymat.sty
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{easymat}[1996/05/15 v0.2]

\DeclareOption{thinlines}{
   \setlength\@mat@tsize@rule{.3pt}
   \setlength\@mat@tsize@dash{.15pt}
}

\DeclareOption{thiklines}{
   \setlength\@mat@tsize@rule{1pt}
   \setlength\@mat@tsize@dash{.4pt}
}

\newlength\@mat@tsize@rule \setlength\@mat@tsize@rule{.4pt}
\newlength\@mat@tsize@dash \setlength\@mat@tsize@dash{.2pt}

\newlength{\@mat@row@sep}
\newcounter{@mat@level}
\setcounter{@mat@level}{0}

\newlength\@mat@col@sep                              \newbox\@mat@box
\newlength\@mat@col@sepi   \newcounter{@mat@ncoli}   \newbox\@mat@boxi
\newlength\@mat@col@sepii  \newcounter{@mat@ncolii}  \newbox\@mat@boxii
\newlength\@mat@col@sepiii \newcounter{@mat@ncoliii} \newbox\@mat@boxiii
\newlength\@mat@col@sepiv  \newcounter{@mat@ncoliv}  \newbox\@mat@boxiv
\newlength\@mat@col@sepv   \newcounter{@mat@ncolv}   \newbox\@mat@boxv

\ProcessOptions

\newlength\@mat@tlen@dash  \setlength\@mat@tlen@dash{4pt}
\newlength\@mat@len@dash   \setlength\@mat@len@dash{.4\@mat@tlen@dash}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\@mat@hdot{\vrule width  \@mat@tsize@dash%
                      height 0.5\@mat@tsize@dash %
                      depth  0.5\@mat@tsize@dash}

\def\@mat@vdot{\hrule width  \@mat@tsize@dash%
                      height 0.5\@mat@tsize@dash %
                      depth  0.5\@mat@tsize@dash}

\def\@mat@h@dash{\vrule width  \@mat@len@dash%
                        height 0.5\@mat@tsize@dash %
                        depth  0.5\@mat@tsize@dash}
                 
\def\@mat@v@dash{\hrule width  \@mat@tsize@dash%
                        height \@mat@len@dash%
                        depth  0pt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\@mat@vdots{\hbox to \@mat@tsize@rule{\hfil\vbox to\ht\thr@@{%
   \leaders\vbox to \@mat@tlen@dash {\vfil\@mat@vdot\vfil}\vfill}%
   \hfil}}
   
\def\@mat@vtrat{\hbox to \@mat@tsize@rule{\hfil\vbox to\ht\thr@@{%
   \leaders\vbox to \@mat@tlen@dash%
        {\vfil\@mat@v@dash\vfil\@mat@vdot}\vfill}%
   \hfil}}

\def\@mat@vdash{\hbox to \@mat@tsize@rule{\hfil\vbox to\ht\thr@@{%
   \leaders\vbox to \@mat@tlen@dash {\vfil\@mat@v@dash\vfil}\vfill}%
   \hfil}}
   
\def\@mat@vrule{\vbox to\ht\thr@@{%
   \leaders\vrule width \@mat@tsize@rule\vfill\kern\z@}}
                
\def\@mat@hdots{%
   \cleaders\hbox to \@mat@tlen@dash {\hfil\@mat@hdot\hfil}\hfill}

\def\@mat@hdash{%
   \cleaders\hbox to \@mat@tlen@dash {\hfil\@mat@h@dash\hfil}\hfill}

\def\@mat@htrat{%
   \cleaders\hbox to \@mat@tlen@dash {\hfil\@mat@h@dash\hfil\@mat@hdot}\hfill}

\def\@mat@hrule{%
   \leaders\hrule height \@mat@tsize@rule\hfill\kern\z@}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newif\if@mat@first
\newif\if@mat@last

\def\@mat@span#1{%
      \if@mat@first\else\mathstrut\fi\cr%
      \multispan{\arabic{@mat@ncol\roman{@mat@level}}}#1%
      \vrule depth\if@mat@last0pt\else0.5\@mat@row@sep\fi%
             height\if@mat@first0pt\else0.5\@mat@row@sep\fi%
             width0pt\cr}

\def\@mat@CR{\global\@mat@firstfalse\global\@mat@lastfalse\@mat@CR@}
\def\@mat@CR@{\@ifnextchar[\@mat@CR@@{\@mat@CR@@[\z@]}}
\def\@mat@CR@@[#1]{%
   \global\setlength{\@mat@row@sep}{#1}%
   \global\addtolength{\@mat@row@sep}{\@mat@col@sep}%
   \futurelet\@tempb\@mat@CR@@@}
   
\def\@mat@CR@@@{%
   \ifx\@tempb-\def\next##1{\@mat@span{\@mat@hrule}}\else%
   \ifx\@tempb:\def\next##1{\@mat@span{\@mat@hdash}}\else%
   \ifx\@tempb.\def\next##1{\@mat@span{\@mat@hdots}}\else%
   \ifx\@tempb;\def\next##1{\@mat@span{\@mat@htrat}}\else%
      \def\next{\@mat@span{\relax}}%
   \fi\fi\fi\fi\next}
   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\@mat@parse{\setcounter{@mat@ncol\roman{@mat@level}}{\z@}\@mat@open\@mat@parsea}
\def\@mat@parsea{\futurelet\@tempb\@mat@cmd}

\def\@mat@add#1{\g@addto@macro\@mat@pre{#1}}
\def\@mat@adda#1{\edef\@mat@pre{#1\@mat@pre}}
\def\@mat@addc#1{\edef\@mat@prec{#1\@mat@prec}}

\def\@mat@open{\gdef\@mat@last@col{!}%
               \gdef\@mat@pre{\everycr{}\halign\bgroup\hspace{0.5\@mat@col@sep}}%
               \global\let\@mat@prec\@empty}%
\def\@mat@close#1{%
   \ifx*\@mat@last@col\@mat@addc{!}\else\@mat@addc{\@mat@last@col}\fi%
   \@mat@add{\hspace{0.5\@mat@col@sep}\crcr}}%

\def\@mat@cmd{%
    \ifx\@tempb \end\let\next\@mat@close\else%
    \ifx\@tempb l\let\next\@mat@left\else%
    \ifx\@tempb r\let\next\@mat@right\else%
    \ifx\@tempb c\let\next\@mat@center\else%
    \ifx\@tempb |\let\next\@mat@rule\else%
    \ifx\@tempb :\let\next\@mat@rule\else%
    \ifx\@tempb .\let\next\@mat@rule\else%
    \ifx\@tempb ;\let\next\@mat@rule\else%
    \def\next##1{\@mat@parsea}%
       \PackageWarning{easymat}{unrecognized command \meaning\@tempb}%
    \fi\fi\fi\fi\fi\fi\fi\fi%
    \next}

\def\@mat@add@col#1#2{%
   \ifnum0=\value{@mat@ncol\roman{@mat@level}}\else%
   \@mat@add{\hspace{0.5\@mat@col@sep}&\hspace{0.5\@mat@col@sep}}\fi%
   \addtocounter{@mat@ncol\roman{@mat@level}}{\@ne}%
   \@mat@add{#1$\displaystyle{##}$#2}%
   \@mat@addc{\@mat@last@col}%
   \gdef\@mat@last@col{*}%
}

\def\@mat@left#1{\@mat@add@col{}{\hfil}\@mat@parsea}
\def\@mat@right#1{\@mat@add@col{\hfil}{}\@mat@parsea}
\def\@mat@center#1{\@mat@add@col{\hfil}{\hfil}\@mat@parsea}
\def\@mat@rule#1{\gdef\@mat@last@col{#1}\@mat@parsea}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\@mat@c@parse#1#2{\gdef\@mat@pre{\crcr\omit\hfil}\@mat@c@parsea}
\def\@mat@c@parsea{\futurelet\@tempb\@mat@c@cmd}
\def\@mat@c@close#1{\@mat@add{\cr}}%
\def\@mat@c@cmd{%
    \ifx\@tempb\end\let\next\@mat@c@close\else\let\next\@mat@c@rule\fi%
    \next}
\def\@mat@c@rule#1{\@mat@add{&\omit\hfil}\@mat@c@parsea}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\MAT{\@ifnextchar[{\MAT@}{\MAT@[5\@mat@tsize@rule]}}
\def\MAT@[#1]#2{%
   \addtocounter{@mat@level}{\@ne}%
   \expandafter\@mat@parse#2\end%
   \global\expandafter\let\csname @mat@prec\roman{@mat@level}\endcsname\@mat@prec%
   \setlength{\@nameuse{@mat@col@sep\roman{@mat@level}}}{#1}%
   \global\setlength{\@mat@col@sep}{\@nameuse{@mat@col@sep\roman{@mat@level}}}%
   \def\first{\global\@mat@firsttrue\global\@mat@lastfalse\@mat@CR@}
   \def\last{\global\@mat@firstfalse\global\@mat@lasttrue\@mat@CR@}
   \let\\\@mat@CR\setbox\@nameuse{@mat@box\roman{@mat@level}}%
   \vbox\bgroup\lineskip\z@skip\tabskip\z@skip\baselineskip\z@skip%
   \expandafter\@mat@pre}
\def\endMAT{%
   \global\expandafter\let\expandafter\@mat@prec%
      \csname @mat@prec\roman{@mat@level}\endcsname%
   \expandafter\@mat@c@parse\@mat@prec\end%
   \@mat@pre\egroup\egroup%
   \setbox\z@\vbox{\unvbox\@nameuse{@mat@box\roman{@mat@level}}%
                   \global\setbox\@ne=\lastbox}% omit box
   \dimen0\ht\z@\advance\dimen0 by\dp\z@%
   \global\setbox\thr@@=\hbox{\vrule width 0pt depth0pt height\dimen0}%
   \setbox\@ne=\hbox{
      \unhbox\@ne%
      \expandafter\@mat@nextitem\@mat@prec-\end%
      \loop%
        \unskip\global\setbox\@ne=\lastbox%
        \ifhbox\@ne%
        \global\setbox\tw@=\box\@ne%
        \@mat@d@rule{@}%
        \expandafter\@mat@nextitem\@mat@prec-\end%
      \repeat%
   }%
   \vcenter{\vbox spread \@mat@col@sep{\vfil%
            \hbox spread \@mat@col@sep{\hfil%
               \hbox{%
                  \wd\thr@@=0pt\box\thr@@%
                  \hspace{0.5\@mat@tsize@rule}\box\z@%
                  \hspace{0.5\@mat@tsize@rule}%
               }\hfil%
           }\vfil}}%
   \addtocounter{@mat@level}{\m@ne}
   \global\setlength{\@mat@col@sep}{\@nameuse{@mat@col@sep\roman{@mat@level}}}%
}

\def\@mat@nextitem#1#2\end{\@mat@d@rule{#1}\gdef\@mat@prec{#2}}
\def\@mat@d@rule#1{%
    \ifx#1|\@mat@add@box@rule{\@mat@vrule}\else%
    \ifx#1:\@mat@add@box@rule{\@mat@vdash}\else%
    \ifx#1.\@mat@add@box@rule{\@mat@vdots}\else%
    \ifx#1;\@mat@add@box@rule{\@mat@vtrat}\else%
    \ifx#1@\@mat@add@box@rule{%
        \setlength{\@tempdima}{\wd\tw@}%
        \addtolength{\@tempdima}{-\@mat@tsize@rule}%
        \vrule width\@tempdima depth0pt height 0pt}%
    \fi\fi\fi\fi\fi%
}

\def\@mat@add@box@rule#1{%
    \global\setbox\thr@@=\hbox{#1\unhbox\thr@@}}


\endinput
%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%