[Tex/LaTex] Using hyperref’s \hyperlink command inside \caption in figure environment

captionshyperref

I am trying to link an acronym I am using in a figure caption to the nomenclature list in the beginning of my document where it is defined, e.g.:

Fig. 1. This process makes use of ACRONYM to do etc.

In my nomenclature list I of course define ACRONYM. I am trying to achieve this linking using the hyperref package, so naturally, at my list of nomenclature I have something like:

\hypertarget{ACRONYM}{Its definition...}

And at the appropriate figure (where I have a centering command that I have tried to contain with {}, which I don't know how "correct" that may be):

\begin{figure}
    \centering{
    \includegraphics[width=\textwidth]{thepicturefile}
     }
    \caption{This process makes use of \hyperlink{ACRONYM}{ACRONYM} to do etc.}
\end{figure}

But, upon compiling, I get the error:

Argument of \caption@ydblarg has an extra }

and Paragraph ended before \caption@ydblarg was complete.

Does anyone know what may be causing this issue?

I also use the caption package if that is perhaps relevant.

I have tried using \protect before the \hyperlink command too, but then I get additional errors along the lines of paragraph ended before \contentsline was complete and more on extra }.

EDIT: I swear I don't know how this worked, but just tried \protect\hyperlink… again and now it compiles no problem!

So, problem solved I guess.

Best Answer

Protect the command:

\documentclass{article}
\usepackage{caption}
\usepackage{hyperref}

\begin{document}
\hypertarget{ACRONYM}{Its definition...}

\begin{figure}
    blub
   \caption{This process makes use of \protect\hyperlink{ACRONYM}{ACRONYM} to do etc.}
\end{figure}
\end{document}
Related Question