The package easymat

Enrico Bertolazzi Laboratorio di Matematica Applicata e Meccanica Computazionale Dipartimento di Ingegneria Meccanica e Strutturale Università degli Studi di Trento Mesiano, Trento, Italy

                  mailto:enrico.bertolazzi@ing.unitn.it

Abstract—The 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/tabular-like syntax.

Contents

1 Some examples with easymat 2 2 Some example with balancing 4 3 An example with minimal size setting 6 4 An example with various size rules 7 5 The \addpath command 8 6 An example with reentrance 10

Important The 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 easymat.sty in the directory ``old''.

1 Some examples with easymat

Load the package in the usual way:

\documentclass{article}
.
.
\usepackage[thinlines,thiklines]{easymat}
.
.

The options thinlines, and thiklines are self explanatory. easymat provides the MAT environment which is a simple re-implementation of the array/tabular environment, with some limitation and some additional features. The syntax is

\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}

• (eq) or (eq,mx,my). By eq you can balance the rows or the column or both, as shown in this table:

Table 1.

value of x effect
@  no balancing
r  equal rows heights
c  equal column widths
b  equal rows heights and equal column widths
e  equal rows heights and column widths

By mx and 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.

• [ex] or [ex,MX,MY]. By “ex” you can specify the amount of extra space around the item in the MAT environment. The default is 2pt. By MX and MY you can modify the minimum size of the whole table in the TAB environment. This must be a valid measure e.g.10cm.

• The `{cc...c}' is the definition of the columns and their alignment. The possible alignment for the columns are:

Table 2.

c centering
l flush left
r flush right

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{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}
\]

1  1  1 ^{1 \frac{111}{222} 1} 1  1  1  1 1 1 ^{1 \frac{111}{222} 1} ^{1 1 1}

The command \first is used to produce the first top rule. The various separation rules are defined by a character code immediately after the command \\. The available rules for the rows and columns are

Table 3.

nothing no rule
|  solid line (or - for the rows)
:  dash line
;  dot-dash line
.  dotted line
0  solid line with size 1/5 of normal line
1  solid line with size 1/4 of normal line
2  solid line with size 1/3 of normal line
3  solid line with size 1/2 of normal line
4  equivalent to |
5  solid line with size 2 times of normal line
6  solid line with size 3 times of normal line
7  solid line with size 4 times of normal line
8  solid line with size 5 times of normal line
9  solid line with size 6 times of normal line

IMPORTANT: each row must be ended by a \\ unless an error is produced.

The main feature of the MAT environment is that it is reentrant as shown it the following:

\[ \begin{MAT}{0c.c9}
\first-
1 & 2 \\. 3 &
\begin{MAT}{c:c}
  a & b \\.
  c & d \\
\end{MAT} \\-
\end{MAT}
\]

\begin{matrix}1 & 2 \\ 3 & \begin{matrix}a & b \\ c & d \end{matrix} \end{matrix}

IMPORTANT: The package can manage a reentrance of a maximum of 8 levels.

2 Some example with balancing

Here it is showed the effect of various balancing:

\[
\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}
\]

which produce:

1 22 333 ^{\frac{1}{2} 1 1} ^{\frac{1}{\frac{1}{2}} 1 1} ^{1 22 333} ^{\frac{1}{2} 1 1} ^{\frac{1}{\frac{1}{2}} 1 1}  1 22 333 ^{\frac{1}{2} 1 1} ^{\frac{1}{\frac{1}{2}} 1 1} ^{1 22 333} ^{\frac{1}{2} 1 1} ^{\frac{1}{\frac{1}{2}} 1 1}  ^{1  22 333} ^{\frac{1}{2}  1  1} ^{\frac{1}{\frac{1}{2}}  1  1}

3 An example with minimal size setting

It is possible to specify the minimal size of the item inside a “MAT” environment, as shown here

      \[ \left[
        \begin{MAT}(@,50pt,20pt){c.c}
            1 & 22 \\.
            \frac{1}{2} & 1 \\
        \end{MAT}
      \right] \]

[  \begin{matrix}1 & 22 \\ \frac{1}{2} & 1 \end{matrix} ]

It is possible to specify the total minimal size of a MAT environment, as shown here

\[ \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] \]

[ \begin{matrix}1 & 22 \\ \frac{1}{2} & 1 \end{matrix} ] × [ \begin{matrix}x \\ y \end{matrix} ] = [ 2 \frac{3}{2} ]

4 An example with various size rules

This example shows the use of various size rule in MAT environment:

\[ \begin{MAT}(e,10pt,10pt){0c1c2c3c4c5c6c7c8c9}
\first0
* & * & * & * & * & * & * & * & * \\1
* & * & * & * & * & * & * & * & * \\2
* & * & * & * & * & * & * & * & * \\3
* & * & * & * & * & * & * & * & * \\4
* & * & * & * & * & * & * & * & * \\5
* & * & * & * & * & * & * & * & * \\6
* & * & * & * & * & * & * & * & * \\7
* & * & * & * & * & * & * & * & * \\8
* & * & * & * & * & * & * & * & * \\9 \end{MAT} \]
\end{BOX}

\begin{matrix}∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ \\ ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ \\ ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ \\ ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ \\ ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ \\ ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ \\ ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ \\ ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ \\ ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ & ∗ \end{matrix}

5 The \addpath command

Is is possible to add paths to the “MAT” environment. The sintax is the following

\begin{MAT} ...... {...}
...... \\
...... \\
...... \\
\addpath{(`x',`y',`rule')`path'}
.
.
\addpath{(`x',`y',`rule')`path'}
\end{MAT}

where

• x and y are the integer coordinate of the starting corner. The left down corner is at coordinate x = 0, y = 0.

• rule is the code of a valud rule as described in table 3.

• path is a string describing the path. Each letter of the string is a movement coded as follows:

Table 4.

letter direction
l  left movement and drawing
r  right movement and drawing
u  up movement and drawing
d  down movement and drawing

The following example shows the use of \addpath,

\[ \begin{MAT}[5pt]{|ccccc|}
\first-
* & * & * & * & * \\
* & * & * & * & * \\
* & * & * & * & * \\
* & * & * & * & *
\addpath{(1,1,0)ruld}
\addpath{(4,3,;)lldrrdll} \\-
\end{MAT} \]

\begin{matrix}∗ & ∗ & ∗ & ∗ & ∗ \\ ∗ & ∗ & ∗ & ∗ & ∗ \\ ∗ & ∗ & ∗ & ∗ & ∗ \\ ∗ & ∗ & ∗ & ∗ & ∗ \end{matrix}

IMPORTANT: The commands \addpath can be putted anymere before the last \\ command.

This is another example

\[ \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) \]

( \begin{matrix}1 & ∗ & ∗ & ∗ & ∗ & ∗ \\ 0 & 11 & ∗ & ∗ & ∗ & ∗ \\ 0 & 0 & 111 & ∗ & ∗ & ∗ \\ 0 & 0 & 0 & 1111 & ∗ & ∗ \\ 0 & 0 & 0 & 0 & 11111 & ∗ \\ 0 & 0 & 0 & 0 & 0 & 11111 \end{matrix} )

6 An example with reentrance

This final example shows a slightly more complex (reentrant) definition in which the MAT environment is used:

\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 \]

The package easymat 11 It produces the following output:

\begin{matrix}\begin{matrix}\begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} & ♢ & \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} \\ ♢ & \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} & ♢ \\ \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} & ♢ & \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} \end{matrix} & ♣ & \begin{matrix}\begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} & ♢ & \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} \\ ♢ & \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} & ♢ \\ \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} & ♢ & \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} \end{matrix} \\ ♣ & \begin{matrix}\begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} & ♢ & \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} \\ ♢ & \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} & ♢ \\ \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} & ♢ & \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} \end{matrix} & ♣ \\ \begin{matrix}\begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} & ♢ & \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} \\ ♢ & \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} & ♢ \\ \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} & ♢ & \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} \end{matrix} & ♣ & \begin{matrix}\begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} & ♢ & \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} \\ ♢ & \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} & ♢ \\ \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} & ♢ & \begin{aligned}& ♡ \\ ♡ & & ♡ \\ & ♡ \end{aligned} \end{matrix} \end{matrix}