I am using my own icons in a document using
\newcommand{\icon}{\includegraphics[scale=0.2]{myicon.pdf}}
as described in this post.
Now I am trying to use this newcommand in a caption environment, but I get errors
! Argument of \@caption has an extra }.
! Paragraph ended before \@caption was complete.
Is there any way to add figures to the caption environment? or any suggested workaround to this?
Minimal example
\documentclass{article}
\usepackage{graphicx}
\newcommand{\icon}{\includegraphics[scale=0.2]{myicon.pdf}}
\begin{document}
This is an inline \icon % this part compiles good
\begin{figure}
\includegraphics[width=\linewidth]{myfigure}
\caption{This is an \icon in a caption environment.} % this part gives errors
\end{figure}
\end{document}