I'd like to create an environment that basically behaves like amsmath's (v. 2.13) align environment, i.e. line numbering, \label, \tag, \intertext ... are available.
Since I don't want to reinvent the wheel I naively thought I could just use a modified version of \align@preamble (lines 2075ff. of amsmath.sty). However, this won't work if I try to use the cell contents as argument of a command.
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\def\mytest#1{#1}
% when defined without argument there's no problem:
% \def\mytest{\bfseries}
% this is my modified version of \align@preamble
\def\my@align@preamble{%
&\hfil
\strut@
\setboxz@h{\@lign\mytest{##}}% this line causes trouble
\ifmeasuring@\savefieldlength@\fi
\set@field
\tabskip\z@skip
&\setboxz@h{\@lign{}##}%
\ifmeasuring@\savefieldlength@\fi
\set@field
\hfil
\tabskip\alignsep@
}
\newenvironment{test}{%
\let\align@preamble\my@align@preamble
\align}{%
\endalign}
\makeatother
\begin{document}
\begin{test}
a & b \\
c & d
\end{test}
\end{document}
The code above throws the error
! Misplaced alignment tab character &.
\@tempa ->\endgroup &
&
l.31 \end{test}
This let's me guess -- but I might be terribly wrong -- that the command somehow closes the group opened by \halign\bgroup (in \align@ (lines 1546ff.) where \align@preamble is used) but I'm unable to figure out where and/or why that happens. It's not quite so easy to follow the code of amsmath.sty, unfortunately, at least not for me...
Can someone point me to the right direction? Or is there an alternative how I could apply a macro to each cell?
