In the caption of some figures I want to link to files using the attachfile2 package. But when I try to compile the following example with XeTeX, MiKTeX and TeXstudio I get the warning ** WARNING ** Unresolved object reference "atfi_obj_6" found!!!
for the first one and some.pdf
isn't included. another.pdf
is included in the resulting document, but twice.
Does anyone have an idea how to fix this?
\documentclass{article}
\usepackage{caption}
\usepackage{attachfile2}
\usepackage{hyperref}
\begin{document}
\listoffigures
\begin{figure}
\caption[Custom Name]{Some Figure \textattachfile{some.pdf}{Link}}
\end{figure}
\begin{figure}
\caption{Another Figure \textattachfile{another.pdf}{Link}}
\end{figure}
\end{document}
The same problem appears for both figures if there is no \listoffigures
at the beginning.
EDIT
I forgot to mention that I had a look at the *.atfi
which contains checksums of the attached files or their paths as far as I understand. The checksums when using attachfile inside a caption (doesn't work) and when using outside a caption (works fine) are the same, so maybe there is some kind of timing problem?
EDIT 2
Based on Herberts answer I made up an command that leads to captions which look more like the default ones and entries in the list of figures that look like the default ones.
\documentclass{article}
\usepackage{caption}
\usepackage{attachfile2}
\def\mycaption#1#2#3{{\par\centering\refstepcounter{figure}%
\figurename\ \thefigure: #1 \textattachfile{#2}{#3}\par}%
\addcontentsline{lof}{figure}{\protect\numberline {\thefigure}{\ignorespaces #1}}}
\begin{document}
\listoffigures
\begin{figure}
\mycaption{Some Figure}{some.pdf}{Link1}
\end{figure}
\begin{figure}
\caption[Some Figure]{Some Figure}
\end{figure}
\end{document}
This results in the following entries in the *.lof
file, so changes to the style of the list of figures should also apply to the entry produced by this command (I think so because they nearly look the same):
\contentsline {figure}{\numberline {1}{\ignorespaces Some Figure}}{1}{figure.1}
\contentsline {figure}{\numberline {2}{\ignorespaces Some Figure}}{1}{figure.caption.3}
The downside of this solution is that I have to define my custom caption style in two places (I didn't mention that because it wasn't necessary to reproduce my problem). So I would appreciate a solution which uses the default \caption
-command.
But for now this one does the job.
\listoffigures
there will be two such attachments.