The package easybmat

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 easybmat 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.

1 Some examples with easybmat

Load the package in the usual way:

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

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

\begin{BMAT}`(x)'`[2pt]'`{cc...c}'`{cc...c}'
   a & b & ... & n \\
.
\end{BMAT}

(x) is an optional parameter, if present it specify if you want to balance the rows or the column or both, as this table shows:

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

[2pt] an optional paramenter that specify the amount of extra space around the item in the BMAT environment. The default is 2pt.

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

c centering
l flush left
r flush right

the second `{cc...c}' is the definition of the rows their alignment. The possible alignment for the rows are:

c centering
t flush top
b flush bottom

It is possible to produce rules between columns or rows as this example shows:

\[ \begin{BMAT}(b){|l:cr|}{|t;cb|}
1 & 1 & 1 \\
1 & \frac{111}{222} & 1 \\
1 & 1 & 1
\end{BMAT}
\qquad
\begin{BMAT}(b){|r:cl|}{|b;ct|}
1 & 1 & 1 \\
1 & \frac{111}{222} & 1 \\
1 & 1 & 1
\end{BMAT}
\]

which produce the following output:

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

The available rules for the rows and columns are

nothing no rule
|  solid line
:  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

The main feature of the BMAT environment is that it is reentrant:

\[ \begin{BMAT}{0c.c9}{|c.c|}
1 & 2 \\
3 & \begin{BMAT}{c:c}{c:c}
      a & b \\
      c & d
 \end{BMAT}
\end{BMAT}
\]

which produces

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

1.0.1 Some example with balancing

Here it is showed the effect of various balancing

\[
\begin{BMAT}{|c|c|c|}{|c|c|c|}
1 & 22 & 333 \\
\frac{1}{2} & 1 & 1 \\
\frac{1}{\frac{1}{2}} & 1 & 1
\end{BMAT}
\quad
\begin{BMAT}(r){|c|c|c|}{|c|c|c|}
1 & 22 & 333 \\
\frac{1}{2} & 1 & 1 \\
\frac{1}{\frac{1}{2}} & 1 & 1
\end{BMAT}
\quad
\begin{BMAT}(c){|c|c|c|}{|c|c|c|}
1 & 22 & 333 \\
\frac{1}{2} & 1 & 1 \\
\frac{1}{\frac{1}{2}} & 1 & 1
\end{BMAT}
\]
\[
\begin{BMAT}(b){|c|c|c|}{|c|c|c|}
1 & 22 & 333 \\
\frac{1}{2} & 1 & 1 \\
\frac{1}{\frac{1}{2}} & 1 & 1
\end{BMAT}
\quad
\begin{BMAT}(e){|c|c|c|}{|c|c|c|}
1 & 22 & 333 \\
\frac{1}{2} & 1 & 1 \\
\frac{1}{\frac{1}{2}} & 1 & 1
\end{BMAT}
\]

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}

1.0.2 An example with size

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

\[ \begin{BMAT}(e)[5pt]{0c1c2c3c4c5c6c7c8c9}
                    {0c1c2c3c4c5c6c7c8c9}
* & * & * & * & * & * & * & * & * \\
* & * & * & * & * & * & * & * & * \\
* & * & * & * & * & * & * & * & * \\
* & * & * & * & * & * & * & * & * \\
* & * & * & * & * & * & * & * & * \\
* & * & * & * & * & * & * & * & * \\
* & * & * & * & * & * & * & * & * \\
* & * & * & * & * & * & * & * & * \\
* & * & * & * & * & * & * & * & *
\end{BMAT}
\]

which produce

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

1.0.3 An example with reentrance

= This final example shows a slightly more complex (reentrant) definition in which the BMAT 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{BMAT}{|l:c:r|}{.t;c;b.}
       \rec(#2) &      #1  & \rec(#2) \\
             #1 & \rec(#2) & #1       \\
       \rec(#2) &      #1  & \rec(#2)
    \end{BMAT}
  \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}