%%% ====================================================================
%%%  @LaTeX-style-file{
%%%     author          = "Enrico Bertolazzi",
%%%     version         = "0.4",
%%%     date            = "13-JUN-2001",
%%%     filename        = "easybmat.sty",
%%%     address         = "Laboratorio di Matematica Applicata
%%%                        e Meccanica Strutturale,
%%%                        Trento University,
%%%                        Via Mesiano, Trento, Italy",
%%%     FAX             = "+39 (461) 882599",
%%%     email           = "enrico.bertolazzi@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 docbmat.tex.
%%%
%%% COPYING:
%%%   Copyright  1999 Enrico Bertolazzi
%%%
%%%   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.
%%%
%%%  }
%%% ====================================================================%%%
%%%       ___    ____  ___   _   _         ___    ____  ___   _   _     %%%
%%%      /   \  /     /   \  \  /         /   \  /     /   \  \  /      %%%
%%%     /____/ /__   /____/   \/         /____/ /__   /____/   \/       %%%
%%%    /   \  /     /  \      /         /   \  /     /  \      /        %%%
%%%   /____/ /____ /    \    /         /____/ /____ /    \    /         %%%
%%% ====================================================================%%%
%%% v 0.4 13-JUN-2001 changed \@roman with \romannumeral (thanks to Claudio Beccari) 
\def\filedate{2001/06/13}
\def\fileversion{v0.4}
\typeout{Document Style `easybmat'  \fileversion\space<\filedate>.}
%% BEGIN easybmat.sty
%%
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{easy}
\ProvidesPackage{easymat}[\filedate\space\fileversion]

\DeclareOption{thinlines}{%
   \@mat@size@rule=.7pt\relax
   \@mat@size@dash=.5pt\relax
}

\DeclareOption{thiklines}{%
   \@mat@size@rule=1.5pt\relax
   \@mat@size@dash=1.2pt\relax
}

\newdimen\@mat@size@rule\@mat@size@rule=1pt\relax
\newdimen\@mat@size@dash\@mat@size@dash=.7pt\relax

\ProcessOptions

\@easy@disable@space

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

\def\@mat@CR{\futurelet\@tempb\@mat@CR@}
\def\@mat@CR@{%
    \@easy@xdef(@easy@row@align\romannumeral\@easy@level)
        {\@mat@row@align@charracter\csname @easy@row@align\romannumeral\@easy@level\endcsname}
    \xdef\@mat@row@align@charracter{c}
    \def\next{
      \@easy@xdef(@easy@row@rules\romannumeral\@easy@level)
        {@\csname @easy@row@rules\romannumeral\@easy@level\endcsname}
      \crcr
    }%
    \@tfor\@tempa:=.;:-|0123456789\do{%
        \expandafter\ifx\expandafter\@tempb\@tempa
              \def\next##1{
               \@easy@xdef(@easy@row@rules\romannumeral\@easy@level)
                  {\@tempa\csname @easy@row@rules\romannumeral\@easy@level\endcsname}
               \crcr
             }%
             \@break@tfor%
         \fi%
    }
    \next
}

\def\@mat@addcol{\g@addto@macro\@mat@preamble{$\displaystyle{##}$&}}
\def\@mat@make@preamble{%
   \@easy@let(@easy@align){@easy@col@align\romannumeral\@easy@level}%
   \@easy@let(@easy@rules){@easy@col@rules\romannumeral\@easy@level}%
   \gdef\@mat@preamble{%
       \vbox\bgroup\lineskip\z@skip%
                   \tabskip\z@skip%
                   \baselineskip\z@skip%
                   \everycr{}\halign\bgroup}%
   \@easy@rotate\@easy@align%
   \loop%
      \@easy@rotate\@easy@align%
      \edef\@tempa{\@easy@firstchar\@easy@align}%
   \expandafter\ifx\@tempa`\relax\else%
      \@mat@addcol%
   \repeat%
   \g@addto@macro\@mat@preamble{$\displaystyle{##}$\crcr}
}


\def\MAT{\advance\@easy@level\@ne\@easy@ifnextchar({\@MAT}{\@MAT(@)}}
\def\@MAT(#1){
    \def\@mat@split##1,##2,##3,##4\end{
       \@easy@xdef(@mat@balance\romannumeral\@easy@level){##1}%
       \global\@nameuse{@easy@minx\romannumeral\@easy@level}=##2
       \global\@nameuse{@easy@miny\romannumeral\@easy@level}=##3
    }
    \expandafter\@mat@split#1,\z@,\z@, \end
    \@@MAT}

\xdef\@mat@row@align@charracter{c}

\def\@@MAT{\@easy@ifnextchar[{\@@@MAT}{\@@@MAT[2pt]}}

\def\@@@MAT[#1]#2{
    \def\@mat@split##1,##2,##3,##4\end{
       \@easy@xdef(@mat@spread\romannumeral\@easy@level){##1}%
       \global\@nameuse{@easy@maxx\romannumeral\@easy@level}=##2
       \global\@nameuse{@easy@maxy\romannumeral\@easy@level}=##3
    }
    \expandafter\@mat@split#1,\z@,\z@, \end
	\@easy@parse@cols{#2}%
    \@easy@xdef(@easy@row@align\romannumeral\@easy@level){}%
    \@easy@xdef(@easy@row@rules\romannumeral\@easy@level){@}%
    \def\first##1{\@easy@xdef(@easy@row@rules\romannumeral\@easy@level){##1}}%
    \def\aligntop{\xdef\@mat@row@align@charracter{t}}
    \def\alignbottom{\xdef\@mat@row@align@charracter{b}}
	\@mat@make@preamble%
    \def\\{\@mat@CR}%
    \global\let\@easy@path\@empty%
 	\setbox\@nameuse{@easy@box\romannumeral\@easy@level}\@mat@preamble%
}

\def\endMAT{%
	\crcr\egroup\egroup%
    %
    \xdef\@easy@row@align{`\csname @easy@row@align\romannumeral\@easy@level\endcsname}%
    \xdef\@easy@row@rules{`\csname @easy@row@rules\romannumeral\@easy@level\endcsname}%
	%
    \@easy@glet(@easy@mainbox)   {@easy@box\romannumeral\@easy@level}%
    \@easy@glet(@easy@col@align) {@easy@col@align\romannumeral\@easy@level}%
    \@easy@glet(@easy@col@rules) {@easy@col@rules\romannumeral\@easy@level}%
    \@easy@glet(@easy@minx)      {@easy@minx\romannumeral\@easy@level}%
    \@easy@glet(@easy@miny)      {@easy@miny\romannumeral\@easy@level}%
    \@easy@glet(@easy@maxx)      {@easy@maxx\romannumeral\@easy@level}%
    \@easy@glet(@easy@maxy)      {@easy@maxy\romannumeral\@easy@level}%
    %
    \@easy@glet(@easy@balance)   {@mat@balance\romannumeral\@easy@level}%
    \@easy@glet(@easy@spread)    {@mat@spread\romannumeral\@easy@level}%
    %
    \global\let\@easy@size@dash\@mat@size@dash
    \global\let\@easy@size@rule\@mat@size@rule
    %
    \@easy@evaldim%
%     \typeout{Easybmat [row:\the\@easy@nrow,col:\the\@easy@ncol]}
    \@easy@balance@row@col%
    \@easy@buildbox%
    \@easy@vlines%
    \@easy@hlines%
	\vcenter{\hbox{\rlap{\box\@ne}
	               \rlap{\box\tw@}
	               \ifx\@easy@path\@empty\else\@easy@dopath\rlap{\box\thr@@}\fi
	               \box\@easy@mainbox}}%
    \advance\@easy@level\m@ne%
}

\@easy@enable@space

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