In the below example, the \spvec macro generates a column vector nicely in the main body of the document, but it won't compile in the caption.
\documentclass[a4paper]{article}
%% Language and font encodings
\usepackage[english]{babel}
\def\spvec#1{\left(\vcenter{\halign{\hfil$##$\hfil\cr \spvecA#1;;}}\right)}
\def\spvecA#1;{\if;#1;\else #1\cr \expandafter \spvecA \fi}
\begin{document}
A $test=\spvec{1;2}$ vector.
\begin{figure}
\centering
\textbf{IMAGE HERE}
\caption{abc... $\spvec{1;2}$}
\end{figure}
\end{document}
The error is
Illegal parameter number in definition of \reserved@a.
<to be read again>
$
l.17 \caption{abc... $\spvec{1;2}$}
\defonly, if you cannot use high level commands like\newcommand,\renewcommandor\providecommand. In the example even using\DeclareRobustCommand*{\spvec}[1]instead of\def\spvec#1could be a good idea. – Schweinebacke Mar 10 '17 at 11:18