Where is the \matrix command?

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}

Matrices


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.