I have a short command that allows me to highlight some text for internal review purposes. Unfortunately, when I use it in a Caption of a figure it gives me the following error.
Argument of \@textcolor has an extra }. ...MA{This is my comment} More caption text.}
Paragraph ended before \@textcolor was complete. ...MA{This is my comment} More caption text.}
Here is my MWE that generates that error:
\documentclass{article}
\usepackage{graphicx} % For figures and stuff
\usepackage{xcolor} % Colors
\usepackage{soul} % Highlight with \hl
%Colored comments for internal review purposes
\newcommand{\MA}[1]{{\sethlcolor{lime}\hl{#1}}}
\begin{document}
Highlighting \MA{in the text} works fine.
\begin{figure}[htbp!]
\centering
\includegraphics[width=3cm]{example-image}
\caption{This is a picture. \MA{This is my comment} More caption text.}
\label{fig:Examplefigure}
\end{figure}
\end{document}
Best Answer
Macro
\MA
is not robust for moving arguments like figure captions.Use
\protect
:Or define a robust command: