I created a function which handles a superscript followed after the function. I do that by using \@ifnextchar^. Everything works well, except in any pmatrix environment. Why?
As a quick-and-dirty example I created the (useless) function \fv to debug it a little:
\documentclass{report}
\usepackage{amsmath}
\makeatletter
\newcommand{\fv}[1]{
\@ifnextchar^{A}{B}
}
\makeatother
\begin{document}
\begin{align*}
\begin{pmatrix}
\fv{x}, \fv{x}^y
\end{pmatrix} = \fv{x} = \fv{x}^y
\end{align*}
\end{document}
I had expected a result in the form (B,Ay)=B=Ay. But what I get is (B,By)=B=Ay.
Is there a way to detect the superscript in pmatrix environments as well?

%) at the end of lines? – Werner Nov 27 '12 at 20:56