\usemodule[mag-01]

\setuptyping[style=\ttx\setupinterlinespace]
\setupheadertexts[section]

\setupbodyfontenvironment	[default][em=italic]
\def\AmSTeX{AmS\TeX} 

\gdef\ShowExample{
  \blank[small]
  \setupbackground
  \startbackground \typebuffer \stopbackground
  \getbuffer\blank[small]}


\starttext \setups[titlepage] \setups[title]
\definemathalignment
  [gather]
  [n=1,align=middle]
\startbuffer
\definemathmatrix
  [aligned]
  [n=2,distance=0pt,align={right,left}]

\definemathmatrix
  [gathered]
  [n=1,align=middle]

\startformula
  a = \frac{\left(\startaligned
    \NC xy \NC {}+ xy + xy \NR
    \NC    \NC {}+ xy + xy \NR
  \stopaligned \right)}{z}
  = \frac{\left(\startgathered
    \NC xy  + xy + xy \NR
    \NC   {}+ xy + xy \NR
  \stopgathered \right)}{z}
\stopformula
\stopbuffer
\ShowExample

\subsection[sec:split]{split (again)}
\type{mathmatrix} can also be used to define a split environment, with 
equations number at the center of the display.

\startbuffer
\definemathmatrix
  [dosplit]
  [n=2,distance=0pt,align={right,left}]

%D Need to change domatrixNC to have a {} so that bin operators
%D are treated properly

\def\startsplit#1\stopsplit{
  \def\dodomatrixNC
    {\gdef\domatrixNC{\endmath&{}}}
  \startdosplit#1\stopdosplit}
  
\placeformula \startformula \startsplit
  \NC f(x) \NC = (x+2)^2 + 2(x+2) + 3 \NR
  \NC \NC = x^2 + 4x + 4 + 2x + 4 + 3 \NR
  \NC \NC = x^2 + 6x + 11 \NR
\stopsplit \stopformula
\stopbuffer
\ShowExample

\section{Some Problems}

\subsection{What happened to my square brackets?}
% \kern\zeropoint
\startbuffer
\startformula \startgather
  [p] = 100 \NR
  [v] = 200 \NR
\stopgather \stopformula
\stopbuffer
\ShowExample

This is not what you would expect. An easy way to avoid such unexpected 
behavior is to start each line with \tex{NC}.
\startbuffer
\startformula \startgather
  \NC [p] = 100 \NR
  \NC [v] = 200 \NR
\stopgather \stopformula
\stopbuffer
\ShowExample

\section{Compatibility with \type{amsmath}}
\tex{startalign} provides a compatibility mode with \type{amsmath} syntax, 
which makes it easier to reuse work written in \LATEX.
\startbuffer
\placeformula \startformula \startalign
  f(x) &= x^3 + 2x^2 + 3 \\
  f'(x) &= 3x^2 + 4x \\
\stopalign \stopformula
\stopbuffer
\ShowExample

However, Hans does not like the syntax, especially the {\em loose label} for 
referring equations. This compatibility feature may disappear in the future. So, 
I suggest not to use it. There are subtle differences from the \type{amsmath} 
syntax, and it is much easier (and logical) to follow the \CONTEXT\ syntax.

\section{Missing Features}
As compared to \AmSTeX\ and \type{amsmath} package of \LATEX, the only display 
math environment missing from \CONTEXT\ is \type{multline}. I do not 
completely understand what is the expected behavior of \type{multline} 
environment. If someone understands what it is supposed to do, and needs that 
feature, make a feature request :)

Subformula numbering is a kludge. The subformula number needs to be specified 
manually.  Using mixed formula and subformula number needs some user 
intervention.  However, it is possible to make these transparent by defining 
your own macros.


\stoptext
\setups[lastpage] 
