# [texhax] matrices

Philip TAYLOR [PC336/H-XP] P.Taylor at Rhul.Ac.Uk
Tue Sep 9 23:06:51 CEST 2003

Well, presumably the only hard bit is interpolating the {ccc}
(for $n$ c's, where $n$ is unknown in advance).  If that is the
case, you could always use the inbuilt facilities of \halign
to arbitrarily replicate a field in the preamble.  So, using
Plain TeX notation, you might write :

\let \\ = \cr
\def \matrix #1{\left ( \vcenter \bgroup \halign \bgroup &\hfil ##\hfil\cr #1\crcr \egroup \egroup \right )}
\matrix{a & b & c \\ d & e & f \\ g & h & i}
\matrix{a & b \\ c & d \\ f & g}
\end

Philip Taylor, RHBNC
--------
Joe Corneli wrote:
>
> Hello,
>
> I'm new to this list, and new to TeX hacking, though I've been using
> LaTeX to typeset math for about 4 or 5 years.  One thing that I haven't
> been able to get satisfied with is the way one has to enter matrices,
> viz.,
>
> $\left ( \begin{array}{ccc} > a & b & c \\ d & e & f \\ g & h & i > \end{array} \right )$
>
> I would like to compress all of this into a macro like
> the following:
>
> $\matrix{a & b & c \\ d & e & f \\ g & h & i}$
>
> The trick is detecting the number of columns dynamically, since I'd like
> the same macro to work in this setting too:
>
> $\matrix{a & b \\ c & d \\ f & g}$
>
> Is it possible to do something like this?  And can anyone suggest a way
> to get started on it?  Maybe there is already something built-in that I
> just don't know about, I'd love to hear about that too.
>
> Joe
> _______________________________________________
> TeX FAQ: http://faq.tug.org/