I would like an extra command to be run in the captions using the \subfloat command from the subfig package. With normal captions, I just redefine \captionfont, but this doesn't work for captions of subfloats.
I have tried (the command I want to run is \sansmath:
\documentclass{article}
\usepackage{caption}
\renewcommand{\captionfont}{\footnotesize\sffamily}
\usepackage{sansmath}
\usepackage[textfont=sf]{subfig}
\let\bensubfloat\subfloat
\renewcommand{\subfloat}[2][]{\bensubfloat[\sansmath #1]{#2}}
\begin{document}
\begin{figure}
\subfloat[Subcaption $1+1$]{\framebox[3cm]{First}} \hfill
\subfloat[Subcaption $1+a$]{\framebox[3cm]{Second}}
\caption{Main caption}
\end{figure}
\end{document}
This gives the desired output, but also many errors.