\documentclass[a4paper]{article} % \usepackage{times} \usepackage{easytitle}% \usepackage{easymat}% \let\package\texttt % so \package{foo} comes out in \tt \let\envname\textsf % so \envname{foo} comes out as \sf \newbox\tempbox \def\BOX{% \setbox\tempbox\hbox\bgroup \begin{minipage}{0.9\textwidth} } \def\endBOX{% \end{minipage} \egroup \par\bigskip \begin{center} \fboxsep=10pt\fbox{\box\tempbox} \end{center} \bigskip\par } \title{The package \package{easymat}} \author[E. Bertolazzi]{Enrico Bertolazzi} \address{ Laboratorio di Matematica Applicata e Meccanica Computazionale\\ Dipartimento di Ingegneria Meccanica e Strutturale\\ Universit\`a degli Studi di Trento\\ Mesiano, Trento, Italy} \mailto{enrico.bertolazzi@ing.unitn.it} \begin{document} \maketitle \begin{abstract} The \package{easymat} package is a macro package for writing block matrices, with equal column widths or equal rows heights or both, with various kinds of rules~(lines) between rows and columns. It uses an array/ta\-bular-like syntax. \end{abstract} \tableofcontents \vfill {\bfseries Important} The package \package{easymat} was improved a lot between version 0.1 to version 0.2. Unfortunately, due to some technical choice, matrices written for version 0.2 are incompatible (because of few modification) with matrices written for version 0.1. If you prefer the old style you can find \verb+easymat.sty+ in the directory \verb+``old''+. \newpage \section{Some examples with \package{easymat}} Load the package in the usual way: \begin{BOX} \begin{verbatim} \documentclass{article} . . \usepackage[thinlines,thiklines]{easymat} . . \end{verbatim} \end{BOX} The options \texttt{thinlines}, and \texttt{thiklines} are self explanatory. \package{easymat} provides the \envname{MAT}~environment which is a simple re-implementation of the array/tabular environment, with some limitation and some additional features. The syntax is \begin{BOX} \begin{verbatim} \begin{MAT}`(eq)'`[ex]'`{cc...c}' a & b & ... & n \\ . \end{MAT} or \begin{MAT}`(eq,mx,my)'`[ex,MX,MY]'`{cc...c}' a & b & ... & n \\ . \end{MAT} \end{verbatim} \end{BOX} \begin{itemize} \item \verb+(eq)+ or \verb+(eq,mx,my)+. By \verb+eq+ you can balance the rows or the column or both, as shown in this table: \begin{center} \textbf{Table 1.} \\[1em] \begin{tabular}{|l|l|} \hline value of $x$ & effect \\ \hline \verb+@+ & no balancing \\ \verb+r+ & equal rows heights \\ \verb+c+ & equal column widths \\ \verb+b+ & equal rows heights and equal column widths \\ \verb+e+ & equal rows heights and column widths \\ \hline \end{tabular} \end{center} By \verb+mx+ and \verb+my+ you can modify the minimum size of the box in the MAT environment. This must be a valid measure e.g. 2pt. This is useful in writing matrices an vectors. \item \verb+[ex]+ or \verb+[ex,MX,MY]+. By ``\verb+ex+'' you can specify the amount of extra space around the item in the \envname{MAT} environment. The default is \verb+2pt+. By \verb+MX+ and \verb+MY+ you can modify the minimum size of the whole table in the \envname{TAB} environment. This must be a valid measure e.g.10cm. \item The \verb+`{cc...c}'+ is the definition of the columns and their alignment. The possible alignment for the columns are: \begin{center} \textbf{Table 2.} \\[1em] \begin{tabular}{|l|l|} \hline \verb+c+ & centering \\ \verb+l+ & flush left \\ \verb+r+ & flush right \\ \hline \end{tabular} \end{center} \end{itemize} \textbf{IMPORTANT:} The package can manage matrices with a maximum of $30$ rows by $30$ columns. It is possible to produce rules between columns or rows as this example shows: \begin{BOX} \begin{verbatim} \[ \begin{MAT}(b){|l:cr|} \first- \aligntop 1 & 1 & 1 \\; 1 & \frac{111}{222} & 1 \\ \alignbottom 1 & 1 & 1 \\- \end{MAT} \qquad \begin{MAT}(b){|r:cl|} \first- \alignbottom 1 & 1 & 1 \\; 1 & \frac{111}{222} & 1 \\ \aligntop 1 & 1 & 1 \\- \end{MAT} \] \end{verbatim} \[ \begin{MAT}(b){|l:cr|} \first- \aligntop 1 & 1 & 1 \\; 1 & \frac{111}{222} & 1 \\ \alignbottom 1 & 1 & 1 \\- \end{MAT} \qquad \begin{MAT}(b){|r:cl|} \first- \alignbottom 1 & 1 & 1 \\; 1 & \frac{111}{222} & 1 \\ \aligntop 1 & 1 & 1 \\- \end{MAT} \] \end{BOX} The command \verb+\first+ is used to produce the first top rule. The various separation rules are defined by a character code immediately after the command \verb+\\+. The available rules for the rows and columns are \begin{center} \textbf{Table 3.} \\[1em] \begin{tabular}{|l|l|} \hline nothing & no rule \\ \verb+|+ & solid line (or \verb+-+ for the rows) \\ \verb+:+ & dash line \\ \verb+;+ & dot-dash line \\ \verb+.+ & dotted line \\ \verb+0+ & solid line with size $1/5$ of normal line \\ \verb+1+ & solid line with size $1/4$ of normal line \\ \verb+2+ & solid line with size $1/3$ of normal line \\ \verb+3+ & solid line with size $1/2$ of normal line \\ \verb+4+ & equivalent to \verb+|+ \\ \verb+5+ & solid line with size $2$ times of normal line \\ \verb+6+ & solid line with size $3$ times of normal line \\ \verb+7+ & solid line with size $4$ times of normal line \\ \verb+8+ & solid line with size $5$ times of normal line \\ \verb+9+ & solid line with size $6$ times of normal line \\ \hline \end{tabular} \end{center} \textbf{IMPORTANT:} each row \textbf{must} be ended by a \verb+\\+ unless an error is produced. The main feature of the \envname{MAT}~environment is that it is reentrant as shown it the following: \begin{BOX} \begin{verbatim} \[ \begin{MAT}{0c.c9} \first- 1 & 2 \\. 3 & \begin{MAT}{c:c} a & b \\. c & d \\ \end{MAT} \\- \end{MAT} \] \end{verbatim} \[ \begin{MAT}{0c.c9} \first- 1 & 2 \\. 3 & \begin{MAT}{c:c} a & b \\. c & d \\ \end{MAT} \\- \end{MAT} \] \end{BOX} \textbf{IMPORTANT:} The package can manage a reentrance of a maximum of $8$ levels. \section{Some example with balancing} Here it is showed the effect of various balancing: \begin{BOX} \begin{verbatim} \[ \begin{MAT}{|c|c|c|} \first- 1 & 22 & 333 \\- \frac{1}{2} & 1 & 1 \\- \frac{1}{\frac{1}{2}} & 1 & 1 \\- \end{MAT} \quad \begin{MAT}(r){|c|c|c|} \first- 1 & 22 & 333 \\- \frac{1}{2} & 1 & 1 \\- \frac{1}{\frac{1}{2}} & 1 & 1 \\- \end{MAT} \quad \begin{MAT}(c){|c|c|c|} \first- 1 & 22 & 333 \\- \frac{1}{2} & 1 & 1 \\- \frac{1}{\frac{1}{2}} & 1 & 1 \\- \end{MAT} \] \[ \begin{MAT}(b){|c|c|c|} \first- 1 & 22 & 333 \\- \frac{1}{2} & 1 & 1 \\- \frac{1}{\frac{1}{2}} & 1 & 1 \\- \end{MAT} \quad \begin{MAT}(e){|c|c|c|} \first- 1 & 22 & 333 \\- \frac{1}{2} & 1 & 1 \\- \frac{1}{\frac{1}{2}} & 1 & 1 \\- \end{MAT} \] \end{verbatim} \end{BOX} which produce: \begin{BOX} \[ \begin{MAT}{|c|c|c|} \first- 1 & 22 & 333 \\- \frac{1}{2} & 1 & 1 \\- \frac{1}{\frac{1}{2}} & 1 & 1 \\- \end{MAT} \quad \begin{MAT}(r){|c|c|c|} \first- 1 & 22 & 333 \\- \frac{1}{2} & 1 & 1 \\- \frac{1}{\frac{1}{2}} & 1 & 1 \\- \end{MAT} \quad \begin{MAT}(c){|c|c|c|} \first- 1 & 22 & 333 \\- \frac{1}{2} & 1 & 1 \\- \frac{1}{\frac{1}{2}} & 1 & 1 \\- \end{MAT} \] \[ \begin{MAT}(b){|c|c|c|} \first- 1 & 22 & 333 \\- \frac{1}{2} & 1 & 1 \\- \frac{1}{\frac{1}{2}} & 1 & 1 \\- \end{MAT} \quad \begin{MAT}(e){|c|c|c|} \first- 1 & 22 & 333 \\- \frac{1}{2} & 1 & 1 \\- \frac{1}{\frac{1}{2}} & 1 & 1 \\- \end{MAT} \] \end{BOX} \section{An example with minimal size setting} It is possible to specify the minimal size of the item inside a ``MAT'' environment, as shown here \begin{BOX} \begin{verbatim} \[ \left[ \begin{MAT}(@,50pt,20pt){c.c} 1 & 22 \\. \frac{1}{2} & 1 \\ \end{MAT} \right] \] \end{verbatim} \[ \left[ \begin{MAT}(@,50pt,20pt){c.c} 1 & 22 \\. \frac{1}{2} & 1 \\ \end{MAT} \right] \] \end{BOX} It is possible to specify the total minimal size of a \envname{MAT} environment, as shown here \begin{BOX} \begin{verbatim} \[ \left[ \begin{MAT}(e)[2pt,3cm,3cm]{c.c} 1 & 22 \\. \frac{1}{2} & 1 \\ \end{MAT} \right] \times \left[ \begin{MAT}(e)[2pt,0pt,3cm]{c} x \\. y \\ \end{MAT} \right] = \left[ \begin{MAT}(e)[2pt,1cm,3cm]{c} 2 \\. \frac{3}{2} \\ \end{MAT} \right] \] \end{verbatim} \[ \left[ \begin{MAT}(e)[2pt,3cm,3cm]{c.c} 1 & 22 \\. \frac{1}{2} & 1 \\ \end{MAT} \right] \times \left[ \begin{MAT}(e)[2pt,0pt,3cm]{c} x \\. y \\ \end{MAT} \right] = \left[ \begin{MAT}(e)[2pt,1cm,3cm]{c} 2 \\. \frac{3}{2} \\ \end{MAT} \right] \] \end{BOX} \section{An example with various size rules} This example shows the use of various size rule in \envname{MAT} environment: \begin{BOX} \begin{verbatim} \[ \begin{MAT}(e,10pt,10pt){0c1c2c3c4c5c6c7c8c9} \first0 * & * & * & * & * & * & * & * & * \\1 * & * & * & * & * & * & * & * & * \\2 * & * & * & * & * & * & * & * & * \\3 * & * & * & * & * & * & * & * & * \\4 * & * & * & * & * & * & * & * & * \\5 * & * & * & * & * & * & * & * & * \\6 * & * & * & * & * & * & * & * & * \\7 * & * & * & * & * & * & * & * & * \\8 * & * & * & * & * & * & * & * & * \\9 \end{MAT} \] \end{BOX} \end{verbatim} \[ \begin{MAT}(e,10pt,10pt){0c1c2c3c4c5c6c7c8c9} \first0 * & * & * & * & * & * & * & * & * \\1 * & * & * & * & * & * & * & * & * \\2 * & * & * & * & * & * & * & * & * \\3 * & * & * & * & * & * & * & * & * \\4 * & * & * & * & * & * & * & * & * \\5 * & * & * & * & * & * & * & * & * \\6 * & * & * & * & * & * & * & * & * \\7 * & * & * & * & * & * & * & * & * \\8 * & * & * & * & * & * & * & * & * \\9 \end{MAT} \] \end{BOX} \section{The \texttt{\char`\\addpath} command} Is is possible to add paths to the ``MAT'' environment. The sintax is the following \begin{verbatim} \begin{MAT} ...... {...} ...... \\ ...... \\ ...... \\ \addpath{(`x',`y',`rule')`path'} . . \addpath{(`x',`y',`rule')`path'} \end{MAT} \end{verbatim} where \begin{itemize} \item \verb+x+ and \verb+y+ are the integer coordinate of the starting corner. The left down corner is at coordinate $x=0$, $y=0$. \item \verb+rule+ is the code of a valud rule as described in table 3. \item \verb+path+ is a string describing the path. Each letter of the string is a movement coded as follows: \begin{center} \textbf{Table 4.} \\[1em] \begin{tabular}{|l|l|} \hline letter & direction \\ \hline \verb+l+ & left movement and drawing \\ \verb+r+ & right movement and drawing \\ \verb+u+ & up movement and drawing \\ \verb+d+ & down movement and drawing \\ \hline \end{tabular} \end{center} \end{itemize} The following example shows the use of \verb+\addpath+, \begin{BOX} \begin{verbatim} \[ \begin{MAT}[5pt]{|ccccc|} \first- * & * & * & * & * \\ * & * & * & * & * \\ * & * & * & * & * \\ * & * & * & * & * \addpath{(1,1,0)ruld} \addpath{(4,3,;)lldrrdll} \\- \end{MAT} \] \end{verbatim} \[ \begin{MAT}[5pt]{|ccccc|} \first- * & * & * & * & * \\ * & * & * & * & * \\ * & * & * & * & * \\ * & * & * & * & * \addpath{(1,1,0)ruld} \addpath{(4,3,;)lldrrdll} \\- \end{MAT} \] \end{BOX} \textbf{IMPORTANT:} The commands \verb+\addpath+ can be putted anymere \textbf{before} the last \verb+\\+ command. This is another example \begin{BOX} \begin{verbatim} \[ \left(\begin{MAT}[5pt]{cccccc} 1 & * & * & * & * & * \\ 0 & 11 & * & * & * & * \\ 0 & 0 & 111 & * & * & * \\ 0 & 0 & 0 & 1111 & * & * \\ 0 & 0 & 0 & 0 & 11111 & * \\ 0 & 0 & 0 & 0 & 0 & 11111 \addpath{(0,5,.)rdrdrdrdrd} \\ \end{MAT}\right) \] \end{verbatim} \[ \left(\begin{MAT}[5pt]{cccccc} 1 & * & * & * & * & * \\ 0 & 11 & * & * & * & * \\ 0 & 0 & 111 & * & * & * \\ 0 & 0 & 0 & 1111 & * & * \\ 0 & 0 & 0 & 0 & 11111 & * \\ 0 & 0 & 0 & 0 & 0 & 11111 \addpath{(0,5,.)rdrdrdrdrd} \\ \end{MAT}\right) \] \end{BOX} \section{An example with reentrance} This final example shows a slightly more complex (reentrant) definition in which the \envname{MAT}~environment is used: \begin{BOX} \begin{verbatim} \def\rec(#1){\expandafter\recurse#1-\end} \def\recurse#1#2\end{% \if\noexpand#1-\def\next##1##2{}% \else\let\next=\recursea\fi% \expandafter\next{#1}{#2}% }% \def\recursea#1#2{% \bgroup \begin{MAT}[0pt]{l:c:r} \aligntop \rec(#2) & #1 & \rec(#2) \\; #1 & \rec(#2) & #1 \\; \alignbottom \rec(#2) & #1 & \rec(#2) \\ \end{MAT} \egroup } \[ \recurse\clubsuit\diamondsuit\heartsuit\end \] \end{verbatim} \end{BOX} It produces the following output: \typeout{This example can take a while to compile on small machine, please wait...} \def\rec(#1){\expandafter\recurse#1-\end} \def\recurse#1#2\end{% \if\noexpand#1-\def\next##1##2{}% \else\let\next=\recursea\fi% \expandafter\next{#1}{#2}% }% \def\recursea#1#2{% \bgroup \begin{MAT}[0pt]{l:c:r} \aligntop \rec(#2) & #1 & \rec(#2) \\; #1 & \rec(#2) & #1 \\; \alignbottom \rec(#2) & #1 & \rec(#2) \\ \end{MAT} \egroup } \small \[ \recurse\clubsuit\diamondsuit\heartsuit\end \] \typeout{...thanks, I have done} \end{document}