I am trying to define a command which takes as an argument a string containing ampersands, and replaces every ampersand by a space. Following the ideas in Replacing characters in argument strings, I defined my command as follows:
\DeclareRobustCommand\colvec[1]{%
\saveexpandmode\expandarg
\StrSubstitute{\noexpand#1}&\ [\vectorentries]%
\restoreexpandmode[\vectorentries]^T}
This works great, except in align
environments, where the ampersands get recognized as column markers and latex gets confused. How should I fix my code to work in align
environments as well?
Here is a minimum-non-working-example:
\documentclass{article}
\usepackage{xstring}
\usepackage{amsmath}
\DeclareRobustCommand\colvec[1]{%
\saveexpandmode\expandarg
\StrSubstitute{\noexpand#1}&\ [\vectorentries]%
\restoreexpandmode[\vectorentries]^T}
\begin{document}
\begin{align}
x = \colvec{3 & 3}
\end{align}
\end{document}
{...}
. This should hide the&
fromalign
's scanning mechansim.