The package easymat

Enrico Bertolazzi

Laboratorio di Matematica Applicata Dipartimento di Ingegneria Civile ed Ambientale Università degli Studi di Trento Mesiano, Trento, Italy

                 bertolaz@ing.unitn.it

Abstract The easymat package is a macro package for writing block matrices, with various kinds of rules (lines) between rows or columns, and uses an array/tabular-like syntax.

1 Some examples with easymat

This package was inspired by the package pmat, version 0.1, of Tomás Oliveira e Silva. This beautiful package allows easy construction of partitioned matrices. Unfortunately, at least this version, the package is not reentrant, so you cannot build block matrices which contain more block matrices. I have solved this problem writing a similar package with different features (some things have been added and some others avoided), however, the algorithms are essentially the same as those of pmat.

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}`[3pt]'`{ccl:c}'
      a & b & ... & n \\`[2mm]'`;'
   .
   \end{MAT}

where `[3pt]' is an optional spacing between row and columns, `{ccl:c}' is the definition of the column (like tabular or array), `[2mm]' is an optional spacing argument for the row, ‘;’ is an optional definition of the row rule. The main feature of the MAT environment is that it is reentrant:

\[ \left[\begin{MAT}{cc}
     1 & 2 \\
     3 & \left(\begin{MAT}{cc}
              a & b \\
              c & d
         \end{MAT}\right)
   \end{MAT}\right]
\]

which produces

[ \begin{matrix}1 & 2 \\ 3 & ( \begin{matrix}a & b \\ c & d \end{matrix} ) \end{matrix} ]

As in tabular or array it is possible to define columns as rules or dashes:

\[  \begin{MAT}{|c:c;rl}
         1 & b & c & f\\
         1 & 2 & 3 & h\\
         1 & b & csssss & \\
         1 & b & c & \frac{1}{2} \\
         A & B & C & d
   \end{MAT}
\]

produces

\begin{matrix}1 & b & c & f \\ 1 & 2 & 3 & h \\ 1 & b & csssss \\ 1 & b & c & \frac{1}{2} \\ A & B & C & d \end{matrix}

r, c, l mean “right”, “center”, and “left” alignment. The available rules for the columns are

nothing no rule
|  solid line
:  dash line
;  dot-dash line
,  dotted line

The lines are ended by \\ for which we can use [ ] as an optional argument for spacing and an optional character for the definition of a rule. The character codes are the following

nothing no rule
-  solid line
:  dash line
;  dot-dash line
,  dotted line

In order to avoid bad alignment for the first (empty) and the last line is better to use the commands \first and \last instead of \\. The following example shows some of the features

\[
 A=\left(\begin{MAT}{|c;c;c|}
         \first:
         1 & b & c \\;
         1 & \begin{MAT}[0pt]{|l:l|}
                \first -11 & 12 \\:
                13 \last-
             \end{MAT} & c \\-
         1 & b & csssss \\:
         1 & b & c \\;
         A & B & C
         \last-
    \end{MAT}\right)
\]

A = ( \begin{matrix}1 & b & c \\ 1 & 1112 13 & c \\ 1 & b & csssss \\ 1 & b & c \\ A & B & C \end{matrix} )

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

\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}{c;c|c}%
       \expandafter\recurse#2-\end &
        #1 &%
         \expandafter\recurse#2-\end \\-%
        #1 &%
         \expandafter\recurse#2-\end &%
          #1 \\;%
         \expandafter\recurse#2-\end &%
          #1 &%
           \expandafter\recurse#2-\end%
    \end{MAT}%
  \egroup%
}
\[ \recurse\clubsuit\diamondsuit\heartsuit\end \]

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}