Matrix Editor

A matrix is a useful way to represent and manipulate linear transformations. They are also used to represent systems of linear equations and many other mathematical structures.

MathLive can display and edit matrices in a variety of ways.

Creating a Matrix

There are several methods to create a matrix in a mathfield.

Using Keyboard Shortcuts

To create a matrix using the keyboard:

  1. Type a parenthesis, square bracket, or curly brace.
  2. Type the first element of the matrix.
  3. Type the ALT/OPTION+TAB key to move to the next column: this will automatically transform the expression into a matrix
  4. Type the ALT/OPTION+RETURN key to move to the next row.

Using the Context Menu

The MathLive context menu provides a convenient way to create a matrix.

To access the context menu right click (or CTRL+click) on the mathfield. The menu is also available by typing ALT+SPACE, or by tapping on the menu button in the mathfield.

To insert a matrix using the context menu select the Insert Matrix menu item, then select the number of rows and columsn of the matrix.

Matrix Borders

The borders of a matrix are parentheses by default. They can be changed to square brackets, curly braces, vertical bars, or none.

To change the border of a matrix right click (or CTRL+click) on the matrix, then select the desired border from the Matrix Border menu item.

In LaTeX, matrices are represented using the \begin{}...\end{} syntax. The argument to the begin command determines the type of matrix and is called the environment.

Inside the environment, the matrix is specified using the & character to separate columns and the \\ character to separate rows.

The following environments are supported:

Environment Description
matrix A matrix with no delimiters
pmatrix A matrix surrounded by parentheses
bmatrix A matrix surrounded by square brackets
Bmatrix A matrix surrounded by curly braces
vmatrix A matrix surrounded by vertical bars
Vmatrix A matrix surrounded by double vertical bars
smallmatrix A matrix with no delimiters, in a smaller font
array A matrix with no delimiters, with control over column alignment
\begin{matrix} a & b \\ c & d \end{matrix}
\[ \begin{matrix} a & b \\ c & d \end{matrix} \]
\begin{pmatrix} a & b \\ c & d \end{pmatrix}
\[ \begin{pmatrix} a & b \\ c & d \end{pmatrix} \]
\begin{bmatrix} a & b \\ c & d \end{bmatrix}
\[ \begin{bmatrix} a & b \\ c & d \end{bmatrix} \]
\begin{Bmatrix} a & b \\ c & d \end{Bmatrix}
\[ \begin{Bmatrix} a & b \\ c & d \end{Bmatrix} \]
\begin{vmatrix} a & b \\ c & d \end{vmatrix}
\[ \begin{vmatrix} a & b \\ c & d \end{vmatrix} \]
\begin{Vmatrix} a & b \\ c & d \end{Vmatrix}
\[ \begin{Vmatrix} a & b \\ c & d \end{Vmatrix} \]
\begin{smallmatrix} a & b \\ c & d \end{smallmatrix}
\[ \begin{smallmatrix} a & b \\ c & d \end{smallmatrix} \]
\begin{array}{cc} a & b \\ c & d \end{array}
\[ \begin{array}{cc} a & b \\ c & d \end{array} \]

Changing the Shape of a Matrix

To add or remove rows or columns right click (or CTRL+click) on the matrix, then select the desired action from the menu. Rows and columns get added or removed relative to the cell the cursor is in.


Changing the spacing of an individual row

The spacing between rows can be adjusted by setting an optional argument to the \\ command. The argument is a length, and can be positive or negative.

For example, the following matrix has no space between columns and a double space between rows:

\begin{pmatrix} a & b \\[1.5em] c & d \end{pmatrix}
\[ \begin{pmatrix} a & b \\[1.5em] c & d \end{pmatrix} \]

Units can be specified using the following abbreviations:

  • em (the width of the letter M in the current font)
  • mu (math unit, 1/18 em)
  • ex (the height of the letter x in the current font)
  • pt (a point, 1/72.27 inch)
  • pc (a pica, 12 points)
  • px (a pixel, 1/96 inch)
  • cm (a centimeter)
  • mm (a millimeter)
  • in (an inch)
  • bp (a big point, 1/72 inch)
  • dd (a didot point, 1238/1157 mm)
  • cc (a cicero, 12 didot points)
  • sp (a scaled point, 65536 sp = 1 pt)

Changing the spacing of all rows

The spacing between rows can be controlled by setting the arraystretch register. The default value is 1.0.

The value of a register can also be modified by using the \renewcommand command. In general, modifying registers using mf.registers is preferred, but using \renewcommand might be handy, for example when rendering static LaTeX.

mf.registers.arraystretch = 2.5
\renewcommand{\arraystretch}{2.5} \begin{pmatrix} a & b \\ c & d \end{pmatrix}
\[ \renewcommand{\arraystretch}{2.5} \begin{pmatrix} a & b \\ c & d \end{pmatrix} \]
\renewcommand{\arraystretch}{0.5} \begin{pmatrix} a & b \\ c & d \end{pmatrix}
\[ \renewcommand{\arraystretch}{0.5} \begin{pmatrix} a & b \\ c & d \end{pmatrix} \]