# Where is the \matrix command?

From what I can see, \matrix was a TeX command, but I cannot seem to find documentation on it.

It works in MathJax, so I wonder if it can be used in LaTeX.

ie this is valid MathJax:

$$\left[ \matrix { newx.x&newy.x&newz.x \\ newx.y&newy.y&newz.y \\ newx.z&newy.z&newz.z } \right]$$


As can be seen on math.stackexchange.

In my LaTeX editor (which uses MikTex underneath), I have to use \begin{matrix} .. \end{matrix}, so I'm wondering what happened to the \matrix command.

-
\usepackage{amsmath} –  Seamus Aug 24 '11 at 20:35
I would upvote purely for the doom avatar. But I've reached the limit cap. Wait, is that doom or wolfenstein? –  Seamus Aug 24 '11 at 20:44
@Seamus: doom and I upped for you :) –  percusse Aug 24 '11 at 20:51
Doom is 18 years old: 1993! OH wow. Makes me feel old... –  Seamus Aug 24 '11 at 21:32
MathJaX is not a reliable guide as to what is available in "standard" LaTeX. It "loads" several packages (or, rather, simulates loading several packages) that are considered "standard" (in that many mathematicians use them). –  Loop Space Aug 25 '11 at 7:23

In addition to some already provided, here are a number of ways of creating matrices in LaTeX. Using

• an array structure to place items in a rigid row/column environment;
• \begin{matrix}...\end{matrix} from the amsmath package, which allows you to specify the matrix delimiters yourself (using \left and \right);
• pmatrix, bmatrix, Bmatrix, vmatrix and Vmatrix variations to the above (also from amsmath) to fix the delimiters to ( ), [ ], { }, | |, and || ||, respectively;
• \bordermatrix{...} which is a TeX command and will specify row and column indicies;
• \kbordermatrix{...} which is similar to the above, but provides more flexibility;
• the blkarray package and the associated blockarray and block environments to construct your matrix.

Here is an example file showing some of the different styles:

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{kbordermatrix}% http://www.hss.caltech.edu/~kcb/TeX/kbordermatrix.sty
\usepackage{blkarray}% http://ctan.org/pkg/blkarray
\begin{document}

$\begin{array}{lc} \verb|array| & \left(\begin{array}{@{}ccc@{}} a & b & c \\ d & e & f \\ g & h & i \end{array}\right) \\[15pt] \verb|matrix| & \left(\begin{matrix} a & b & c \\ d & e & f \\ g & h & i \end{matrix}\right) \\[15pt] \verb|pmatrix| & \begin{pmatrix} a & b & c \\ d & e & f \\ g & h & i \end{pmatrix} \\[15pt] \verb|bmatrix| & \begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{bmatrix} \\[15pt] \verb|Bmatrix| & \begin{Bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{Bmatrix} \\[15pt] \verb|vmatrix| & \begin{vmatrix} a & b & c \\ d & e & f \\ g & h & i \end{vmatrix} \\[15pt] \verb|Vmatrix| & \begin{Vmatrix} a & b & c \\ d & e & f \\ g & h & i \end{Vmatrix} \\[15pt] \verb|bordermatrix| & \bordermatrix{\text{corner}&c_1&c_2&\ldots &c_n\cr r_1&a_{11} & 0 & \ldots & a_{1n}\cr r_2& 0 & a_{22} & \ldots & a_{2n}\cr r_3& \vdots & \vdots & \ddots & \vdots\cr r_4& 0 & 0 &\ldots & a_{nn}} \\[15pt] \verb|kbordermatrix| & \kbordermatrix{\text{corner}&c_1&c_2&\ldots &c_n\cr r_1&a_{11} & 0 & \ldots & a_{1n}\cr r_2& 0 & a_{22} & \ldots & a_{2n}\cr r_3& \vdots & \vdots & \ddots & \vdots\cr r_4& 0 & 0 &\ldots & a_{nn}} \\[25pt] \verb|blkarray| & \begin{blockarray}{[cc]c\}} 11 & 22 & 33 \\ 1 & 2 & 3 \\ \begin{block}{(ll)l\}} 11 & 22 & 33 \\ 1 & 2 & 3 \\ \end{block} 1 & 2 & 3 \end{blockarray} \end{array}$
\end{document}


-
This is the sort of thorough answer we need more of on this site! well done! –  Seamus Aug 24 '11 at 21:24
@Seamus: Thanks! –  Werner Aug 24 '11 at 21:27
I second @Seamus. Great answer, Werner! There should be a Welcome to the Matrix badge. =) –  Paulo Cereda Aug 24 '11 at 23:21
There is not spoon... I mean badge. :-| –  Werner Aug 24 '11 at 23:25
"Unfortunately, no one can tell you what the matrix is. Except for Werner, he seems to do it pretty well." –  Niel de Beaudrap Aug 25 '11 at 0:04

You shouldn't use \matrix{ but \begin{matrix} and \end{matrix} are provided by the amsmath package.

-

It's strongly recommended to use amsmath's matrix features. However, answering your question: you can find the definition of \matrix in plain.tex:

\def\matrix#1{\null\,\vcenter{\normalbaselines\m@th
\ialign{\hfil$##$\hfil&&\quad\hfil$##$\hfil\crcr
\mathstrut\crcr\noalign{\kern-\baselineskip}
#1\crcr\mathstrut\crcr\noalign{\kern-\baselineskip}}}\,}


Related:

\def\pmatrix#1{\left(\matrix{#1}\right)}


You can find plain.tex by typing on the command prompt

kpsewhich plain.tex


which gives on a current standard Windows TeX Live installation, for example

c:/texlive/2011/texmf-dist/tex/plain/base/plain.tex


\matrix is documented in the TeX book and various other TeX documentation. LaTeX documentation is mostly about the more modern matrix environment of amsmath.

-
So, why doesn't \matrix work in my LaTeX implementation, if its part of TeX? –  bobobobo Aug 24 '11 at 23:53
@bobobobo: MathJax also reports the use of environments which includes amsmath's \begin{matrix}...\end{matrix}. Not sure what happened to \matrix{...}. –  Werner Aug 24 '11 at 23:59
@bobobobo: The quick answer is that "plain TeX" is not plain TeX. "plain TeX" is an extension of TeX much as LaTeX is and LaTeX is not built on top of "plain TeX". –  Loop Space Aug 25 '11 at 7:22