I have a custom macro:
\NewDocumentCommand\includefigure{mo}{
...
\caption{#2}
\label{fig:#2}
}
The optional argument is used for the caption and the label. The problem is that when I have parts of this argument formatted like \includefigure{pic}[Hi \textit{there}!] I get errors like "Missing \endcsname inserted." since \label does not allow arguments with commands in it.
Is there a meta-command like \plaintext so I could use \label{\plaintext{fig:#2}} in my command and then \includefigure{pic}[Hi \textit{there}!] would result in \label{fig:Hi there!}?
Or maybe there is an alternative for label.

\ref? Are you really wanting to use\ref{Hi \textit{there}}? – egreg Aug 23 '13 at 14:59