%%% ====================================================================
%%%  @LaTeX-style-file{
%%%     author          = "Enrico Bertolazzi",
%%%     version         = "0.3",
%%%     date            = "15-SEPT-96",
%%%     filename        = "easy.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:
%%%   no documentation
%%%
%%% 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.
%%%
%%%  }
%%% ====================================================================
%%%       ___    ____  ___   _   _      __    __    ____ ______
%%%      /   \  /     /   \  \  /      /  \  /  \  /       /
%%%     /____/ /__   /____/   \/       \    /   / /__     /
%%%    /   \  /     /  \      /         \  /   / /       /
%%%   /____/ /____ /    \    /       \__/  \__/ /       /
%%% ====================================================================
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\@ifundefined{@easy@avoidinclude}{\gdef\@easy@avoidinclude{}}{\endinput}

\newcount\@easy@level\@easy@level=0%

\@for\@tempa:=i,ii,iii,iv,v,vi,vii,viii
\do{\expandafter\global\expandafter\newbox\csname @easy@box\@tempa\endcsname}

\edef\@easy@num@list{i,ii,iii,iv,v,vi,vii,viii,ix,x,xi,xii,xii,xiv}
\@for\@tempa:=\@easy@num@list\do{
   \expandafter\global\expandafter\newdimen\csname @easy@hsize\@tempa\endcsname%
   \expandafter\global\expandafter\newdimen\csname @easy@vsize\@tempa\endcsname%
}

\def\@easy@edef(#1)#2{\expandafter\edef\csname#1\endcsname{#2}}
\def\@easy@xdef(#1)#2{\expandafter\xdef\csname#1\endcsname{#2}}
\def\@easy@gdef(#1)#2{\expandafter\gdef\csname#1\endcsname{#2}}
\def\@easy@def(#1)#2{\expandafter\def\csname#1\endcsname{#2}}

\def\@easy@let(#1)#2{%
    \expandafter\let\csname#1\expandafter\endcsname\csname#2\endcsname} 
\def\@easy@glet(#1)#2{%
    \expandafter\global\expandafter\let\csname#1\expandafter\endcsname\csname#2\endcsname} 
    
\def\@easy@firstchar@#1#2\end{#1}%
\def\@easy@rotate@#1#2\end{#2#1}%
\def\@easy@firstchar#1{\expandafter\@easy@firstchar@ #1-\end}%
\def\@easy@rotate#1{\xdef#1{\expandafter\@easy@rotate@ #1\end}}%

\def\@easy@parse(#1){%
   \global\let\@easy@rules\@empty%
   \global\let\@easy@align\@empty%
   \expandafter\@easy@parsea#1\end%
   \xdef\@easy@rules{`\@easy@rules}%
   \xdef\@easy@align{`\@easy@align}%
}

\def\@easy@parsea{\futurelet\@tempb\@easy@parseb}
\def\@easy@parseb{%parse column separator
    \gdef\next{\xdef\@easy@rules{@\@easy@rules}\@easy@parsec}%
    \expandafter\@tfor\expandafter\@tempa\expandafter:\expandafter=\@easy@list@rules\do{%
         \expandafter\ifx\expandafter\@tempb\@tempa%
             \xdef\@easy@rules{\@tempa\@easy@rules}
             \gdef\next##1{\@easy@parsec}%
             \@break@tfor%
         \fi%
    }
    \next}

\def\@easy@parsec{\futurelet\@tempb\@easy@parsed}
\def\@easy@parsed{% parse column alignment
    \gdef\next{\@easy@parse@error}%
    \ifx\@tempb\end%
       \def\next##1{}% eat end
    \else
       \expandafter\@tfor\expandafter\@tempa\expandafter:\expandafter=\@easy@list@align\do{%
          \expandafter\ifx\expandafter\@tempb\@tempa%
              \xdef\@easy@align{\@tempa\@easy@align}%
              \def\next##1{\@easy@parsea}%
              \@break@tfor%
          \fi%
       }
    \fi%
    \next}

\def\@easy@parse@error{%
    \typeout{unrecognized command \meaning\@tempb\space on line \the\inputlineno}}
    
\newbox\@easy@line@box
\newbox\@easy@seg@box
\newdimen\@easy@dash@len \@easy@dash@len=5pt
\newdimen\@easy@dash@sep \@easy@dash@sep=2pt
\newdimen\@easy@line@len

\def\@easy@h@line#1#2{%
   \global\setbox\@easy@line@box\hbox{#2}%
   \global\setbox\@easy@seg@box\hbox{\unhcopy\@easy@line@box\kern\@easy@dash@sep}%
   \@easy@line@len=#1\advance\@easy@line@len-\wd\@easy@seg@box%
   \loop\ifdim\@easy@line@len>\wd\@easy@line@box%
       \global\setbox\@easy@line@box\hbox{\copy\@easy@seg@box\box\@easy@line@box}%
   \repeat%
   \@easy@line@len=#1%
   \advance\@easy@line@len-\wd\@easy@line@box%
   \advance\@easy@line@len-\@easy@dash@sep%
   \hbox{\box\@easy@line@box\kern\@easy@dash@sep\vrule\@width\@easy@line@len\@height\ht\@easy@seg@box\@depth\z@}%
}  

\def\@easy@v@line#1#2{%
   \global\setbox\@easy@line@box\vbox{#2}%
   \global\setbox\@easy@seg@box\vbox{\unvcopy\@easy@line@box\kern\@easy@dash@sep}%
   \@easy@line@len=#1\advance\@easy@line@len-\ht\@easy@seg@box%
   \loop\ifdim\@easy@line@len>\ht\@easy@line@box%
       \global\setbox\@easy@line@box\vbox{\unvcopy\@easy@seg@box\unvbox\@easy@line@box}%
   \repeat%
   \@easy@line@len=#1%
   \advance\@easy@line@len-\ht\@easy@line@box%
   \advance\@easy@line@len-\@easy@dash@sep%
   \vbox{\unvbox\@easy@line@box\kern\@easy@dash@sep\hrule\@width\wd\@easy@seg@box\@height\@easy@line@len\@depth\z@}%
}  

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\@easy@hdots(#1,#2){\@easy@h@line{#1}{\vrule\@width#2\@height#2\@depth\z@}}
\def\@easy@vdots(#1,#2){\@easy@v@line{#1}{\hrule\@width#2\@height#2\@depth\z@}}

\def\@easy@hdashes(#1,#2){\@easy@h@line{#1}{\vrule\@width\@easy@dash@len\@height#2\@depth\z@}}
\def\@easy@vdashes(#1,#2){\@easy@v@line{#1}{\hrule\@width#2\@height\@easy@dash@len\@depth\z@}}

\def\@easy@hdotdash(#1,#2){\@easy@h@line{#1}{%
\vrule\@width\@easy@dash@len\@height#2\@depth\z@%
\kern\@easy@dash@sep\vrule\@width#2\@height#2\@depth\z@}}

\def\@easy@vdotdash(#1,#2){\@easy@v@line{#1}{%
\hrule\@width#2\@height\@easy@dash@len\@depth\z@%
\kern\@easy@dash@sep\hrule\@width#2\@height#2\@depth\z@}}

\def\@easy@hrule(#1,#2){\hbox{\vrule\@width#1\@height#2\@depth\z@}}
\def\@easy@vrule(#1,#2){\vbox{\hrule\@width#2\@height#1\@depth\z@}}

\def\@easy@defsize#1#2{%
\global\@tempdima=#2%
\ifcase\number#1%
\global\divide\@tempdima5%
\or\global\divide\@tempdima4%
\or\global\divide\@tempdima3%
\or\global\divide\@tempdima2%
\or\or\global\multiply\@tempdima2%
\or\global\multiply\@tempdima3%
\or\global\multiply\@tempdima4%
\or\global\multiply\@tempdima5%
\or\global\multiply\@tempdima6%
\fi}

\def\@easy@hrulekind[#1,#2,#3,#4]{%
\expandafter\ifx#1.\@easy@hdots(#2,#3)\else%
\expandafter\ifx#1;\@easy@hdotdash(#2,#3)\else%
\expandafter\ifx#1:\@easy@hdashes(#2,#3)\else%
\expandafter\ifx#1|\@easy@hrule(#2,#4)\else%
\expandafter\ifx#1@\else%
\@easy@defsize{#1}{#4}\@easy@hrule(#2,\@tempdima)%
\fi\fi\fi\fi\fi%
}

\def\@easy@vrulekind[#1,#2,#3,#4]{%
\expandafter\ifx#1.\@easy@vdots(#2,#3)\else%
\expandafter\ifx#1;\@easy@vdotdash(#2,#3)\else%
\expandafter\ifx#1:\@easy@vdashes(#2,#3)\else%
\expandafter\ifx#1|\@easy@vrule(#2,#4)\else%
\expandafter\ifx#1@\else%
\@easy@defsize{#1}{#4}\@easy@vrule(#2,\@tempdima)%
\fi\fi\fi\fi\fi%
}

\def\@easy@kernkind[#1,#2,#3]{%
\expandafter\ifx#1.\expandafter\kern#2\else%
\expandafter\ifx#1;\expandafter\kern#2\else%
\expandafter\ifx#1:\expandafter\kern#2\else%
\expandafter\ifx#1|\expandafter\kern#3\else%
\expandafter\ifx#1@\else%
\@easy@defsize{#1}{#3}\expandafter\kern\@tempdima%
\fi\fi\fi\fi\fi%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%    4 3 2
%    5 0 1
%    6 7 8
%
\def\@easy@hbox@num[#1,#2,#3,#4]{%
    \edef\@tempa{\ifcase#1c \or r \or r \or c \or l \or l \or l \or c \or r \fi}%
    \edef\@tempb{\ifcase#1c \or c \or t \or t \or t \or c \or b \or b \or b \fi}%
    \@easy@hbox[\@tempa,\@tempb,#2,#3,#4]
}

\def\@easy@hbox[#1,#2,#3,#4,#5,#6]{%
\hbox{\vbox to#4{\expandafter\ifx#2t\else\vfil\fi%
\kern#5\hbox to#3{\expandafter\ifx#1l\else\hfil\fi%
\kern#5\unhbox#6\kern#5\expandafter\ifx#1r\else\hfil\fi}%
\kern#5\expandafter\ifx#2b\else\vfil\fi}}}
%
%   evaluate dimensions of box of boxes
%
\newcount\@easy@ncol
\newcount\@easy@nrow

\def\@easy@evaldim#1#2{%
    \@for\@tempa:=\@easy@num@list\do{% reset dim list
        \global\@nameuse{@easy@hsize\@tempa}=\z@%
        \global\@nameuse{@easy@vsize\@tempa}=\z@%
    }
    \@tempdimb=#2\advance\@tempdimb#2\relax%
	\setbox0\vbox{%
		\unvcopy#1%
		\global\@easy@nrow=0%
		\loop%
			\unskip\global\setbox\@ne\lastbox%
		\ifhbox\@ne%
		    \global\@easy@ncol=0%
		    \@tempdima\dp\@ne%
		    \advance\@tempdima\ht\@ne%
		    \advance\@tempdima\@tempdimb%
		    \global\advance\@easy@nrow\@ne%
            \global\@nameuse{@easy@vsize\@roman\@easy@nrow}=\@tempdima%
			\setbox0=\hbox{%
				\unhbox\@ne%
				\loop%
                    \unskip\global\setbox\tw@=\lastbox%
				\ifhbox\tw@%
					\global\advance\@easy@ncol\@ne%
		            \@tempdima\wd\tw@\advance\@tempdima\@tempdimb%
		            \ifdim\@tempdima>\@nameuse{@easy@hsize\@roman\@easy@ncol}\relax
		                \global\@nameuse{@easy@hsize\@roman\@easy@ncol}=\@tempdima%
		            \fi%
				\repeat%
			}%
		\repeat%
	}%
}

\def\@easy@balance@cols{%
    \global\@tempdima=\z@%
	\@for\@tempa:=\@easy@num@list\do{%
         \ifdim\@tempdima<\@nameuse{@easy@hsize\@tempa}%
		     \global\@tempdima=\@nameuse{@easy@hsize\@tempa}%
		 \fi%
    }%
    \@for\@tempa:=\@easy@num@list\do{\global\@nameuse{@easy@hsize\@tempa}=\@tempdima}%
}

\def\@easy@balance@rows{%
    \global\@tempdima=\z@%
	\@for\@tempa:=\@easy@num@list\do{%
         \ifdim\@tempdima<\@nameuse{@easy@vsize\@tempa}%
		     \global\@tempdima=\@nameuse{@easy@vsize\@tempa}%
		 \fi%
    }%
    \@for\@tempa:=\@easy@num@list\do{\global\@nameuse{@easy@vsize\@tempa}=\@tempdima}%
}

\def\@easy@balance@equalize{%
    \global\@tempdima=\z@%
	\@for\@tempa:=\@easy@num@list\do{%
         \ifdim\@tempdima<\@nameuse{@easy@vsize\@tempa}%
		     \global\@tempdima=\@nameuse{@easy@vsize\@tempa}%
		 \fi%
         \ifdim\@tempdima<\@nameuse{@easy@hsize\@tempa}%
		     \global\@tempdima=\@nameuse{@easy@hsize\@tempa}%
		 \fi%
    }%
    \@for\@tempa:=\@easy@num@list\do{%
         \global\@nameuse{@easy@hsize\@tempa}=\@tempdima%
         \global\@nameuse{@easy@vsize\@tempa}=\@tempdima%
    }%
}

\def\@easy@balance#1{%
    \expandafter\ifx#1c\@easy@balance@cols\else%
    \expandafter\ifx#1r\@easy@balance@rows\else%
    \expandafter\ifx#1b\@easy@balance@cols\@easy@balance@rows\else%
    \expandafter\ifx#1e\@easy@balance@equalize%
    \fi\fi\fi\fi%
}

\def\@easy@buildbox{%
 	\setbox0=\vbox{\ignorespaces%
  		\unvbox\@easy@mainbox%
  		\@easy@rotate\@easy@rrule%
        \edef\@tempc{\@easy@firstchar\@easy@rrule}%
 		\global\setbox\@easy@mainbox\vbox{\@easy@kern\@tempc}%
        \global\@easy@nrow=0%
		\loop%
            \unskip\global\setbox\@ne=\lastbox%
		\ifhbox\@ne%
            \global\advance\@easy@nrow\@ne%
            \@easy@rotate\@easy@rrule%
            \@easy@rotate\@easy@ralign%
            \edef\@tempc{\@easy@firstchar\@easy@rrule}%
            \@easy@buildboxa%
 		    \global\setbox\@easy@mainbox\vbox{\ignorespaces%
  		        \@easy@kern\@tempc\hbox{\unhbox\tw@}\unvbox\@easy@mainbox}%
        \repeat
  		\@easy@rotate\@easy@rrule% elim `
  		\@easy@rotate\@easy@ralign% elim `
    }
}

\def\@easy@buildboxa{%
    \setbox0\hbox{\ignorespaces%	
        \unhbox\@ne%
  	    \@easy@rotate\@easy@crule%
        \edef\@tempc{\@easy@firstchar\@easy@crule}%
 		\global\setbox\tw@\hbox{\@easy@kern\@tempc}%
        \global\@easy@ncol=0%
		\loop%
             \unskip\global\setbox\@ne=\lastbox%
		\ifhbox\@ne%
             \global\advance\@easy@ncol\@ne%
  		     \@easy@rotate\@easy@crule%
  		     \@easy@rotate\@easy@calign%
		     \edef\@tempa{\@easy@firstchar\@easy@calign}%
		     \edef\@tempb{\@easy@firstchar\@easy@ralign}%
             \edef\@tempc{\@easy@firstchar\@easy@crule}%
 		     \global\setbox\tw@\hbox{\ignorespaces%
 		           \@easy@kern\@tempc%
 		           \@easy@hbox[\@tempa,\@tempb,%
		                       \@nameuse{@easy@hsize\@roman\@easy@ncol},%
		                       \@nameuse{@easy@vsize\@roman\@easy@nrow},%
		                       \@easy@spread,\@ne]%
                   \unhbox\tw@}%
        \repeat
 		\@easy@rotate\@easy@crule%
 		\@easy@rotate\@easy@calign%
    }
}

%%%%%%%%%%%%%%% Vertical lines %%%%%%%%%%%%%%%%%%
\def\@easy@vlines#1{%
     \global\@easy@ncol=0%
     \@easy@rotate\@easy@crule%
     \edef\@tempc{\@easy@firstchar\@easy@crule}%
	 \global\setbox#1\hbox{\@easy@vruledraw\@tempc}%
     \loop%
         \global\advance\@easy@ncol\@ne%
         \@easy@rotate\@easy@crule%
         \edef\@tempc{\@easy@firstchar\@easy@crule}%
     \expandafter\ifx\@tempc`\relax\else%
	     \global\setbox#1\hbox{\ignorespaces%
	         \@easy@vruledraw\@tempc%
	         \kern\@nameuse{@easy@hsize\@roman\@easy@ncol}%
	         \unhbox#1%
	     }%
     \repeat%
}

%%%%%%%%%%%%%%% Horizontal lines %%%%%%%%%%%%%%%%%%
\def\@easy@hlines#1{%
     \global\@easy@nrow=0%
     \@easy@rotate\@easy@rrule%
     \edef\@tempc{\@easy@firstchar\@easy@rrule}%
	 \global\setbox#1\vbox{\@easy@hruledraw\@tempc}%
     \loop%
         \global\advance\@easy@nrow\@ne%
         \@easy@rotate\@easy@rrule%
         \edef\@tempc{\@easy@firstchar\@easy@rrule}%
     \expandafter\ifx\@tempc`\relax\else%
	     \global\setbox#1\vbox{\ignorespaces%
	         \@easy@hruledraw\@tempc%
	         \kern\@nameuse{@easy@vsize\@roman\@easy@nrow}%
	         \unvbox#1%
	     }%
     \repeat%
}

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