# Augmented matrices in ConTeXt?

In LaTeX, I could use:

$\left[\,\begin{array}{rr|r}2&-3&6\\ 3&4&-9\end{array}\,\right]$


However, in ConTeXt, especially if I want right-alignments of columns, I seem to have to use:

\startformula
\left[\,\startmathmatrix[n=2,align={right,right}]
\NC 2 \NC -3 \NR
\NC 3 \NC 4 \NR
\stopmathmatrix\;\right|
\left.\startmathmatrix[n=2,align={right}]
\NC 6 \NR
\NC 9 \NR
\stopmathmatrix\,\right]
\stopformula


which is extremely wordy and clumsy-looking (especially compared with the neat and succinct LaTeX).

So - what is the best way of typesetting augmented matrices in ConTeXt?

Thanks!

-
There was a module written by Giuseppe Bilotta, called amsl, that had support for a \startarray ... \stoparray feature that is supposed to be like that of the AMS Latex module. If you google around you can find the implementation, but for some reason it is no longer on CTAN. –  Charles Stewart Apr 20 '11 at 13:05
The amsl module is available at contextgarden, but I would be really surprised if it works with MkIV (IIR, it also does some font changes, and that interface has changed). The array code should still work. –  Aditya Apr 20 '11 at 15:35

Here is a MWA of an idea mostly for Aditya to look at:

\unprotect
\def\dosetmatrixcolumn#1%
{\letvalue{\??eq:\v!left :\number\eqaligncolumn}\hfil
\letvalue{\??eq:\v!right:\number\eqaligncolumn}\hfil
% this is new:
\doif{#1}\v!rule  {\letvalue{\??eq:\v!left :\number\eqaligncolumn}\relax
\setvalue{\??eq:\v!right:\number\eqaligncolumn}%
{\kern -.5\mathalignmentparameter\c!distance
\vrule
\kern -.5\mathalignmentparameter\c!distance}}%
\doif{#1}\v!left  {\letvalue{\??eq:\v!left :\number\eqaligncolumn}\relax
\letvalue{\??eq:\v!right:\number\eqaligncolumn}\hfil}%
\doif{#1}\v!right {\letvalue{\??eq:\v!left :\number\eqaligncolumn}\hfil
\letvalue{\??eq:\v!right:\number\eqaligncolumn}\relax }%
\doif{#1}\v!middle{\letvalue{\??eq:\v!left :\number\eqaligncolumn}\hfil
\letvalue{\??eq:\v!right:\number\eqaligncolumn}\hfil}}
\protect

\definemathmatrix
[augmentedarray]
[n=4,left={\left[\,},right={\,\right]},align={right,right,rule,right}]

\starttext

\startformula
\startaugmentedarray
\NC 2 \NC -3 \NC \NC 6 \NR
\NC 3 \NC  4 \NC \NC 9 \NR
\stopaugmentedarray
\stopformula

\stoptext


There are two things wrong with this bit of code:

• the internal macro \dosetmatrixcolumn needs redefinition which should be done in context core itself, not as part of a document.
• the \NC \NC is a little ugly.

still, it saves a lot of typing.

-
Isn't \processaction better than a bunch of \doifs? –  Aditya Jul 27 '11 at 5:56
I think that it is better to have a separate syntax for rules (and braces), something along the lines of TABLE macros. –  Aditya Jul 27 '11 at 5:58

Not a real answer, but the following codes give the same result

$\left[\begin{array}{@{}rr|r@{}}2&-3&6\\ 3&4&-9\end{array}\right]$
\left[\openup1\jot\offinterlineskip\vcenter{\halign{% \strut \hfil#\hskip\arraycolsep& \hskip\arraycolsep\hfil#\hskip\arraycolsep\kern-.2pt\vrule\kern-.2pt& \hskip\arraycolsep\hfil#\cr 2&-3&6\cr 3&4&-9\cr}} \right]


It's just a matter of teaching ConTeXt to do the \halign. Note that amsmath prefers tight spacing of the delimiters, as can be seen with the bmatrix environment, but that's a question of taste.

-