2

The MWE below gives a warning: "warning (pdf backend): ignoring duplicate destination with the name 'section.1'". The warning disappears when commenting out either the option "localanchorname" or \usepackage{caption}. Can this warning be eliminated (not silenced) while keeping both?

\documentclass{article}
\PassOptionsToPackage{%
  localanchorname%
}{hyperref}

\usepackage{caption}
\usepackage{hyperref}

\begin{document}
\section{Heading One}
xxx

\begin{figure}
\end{figure}

\end{document}
4

Basically caption is not compatible to the localanchorname option as it sets the destination name in a group.

I don't think that the option is very useful, it is much better to put the label where it belongs, but if you need it you will have to reset the destination after the group:

\documentclass{article}
\PassOptionsToPackage{%
  localanchorname%
}{hyperref}

\usepackage{caption}
\makeatletter
\AtBeginDocument{%
\renewcommand*\caption@makestart[1]{%
      \begingroup
        \Hy@hypertexnamesfalse
        \hyper@makecurrent{#1.caption}%
        \global\let\my@currentHref\HyperGlobalCurrentHref
      \endgroup
       \let\@currentHref\my@currentHref
      \caption@Debug{hypcap start=\@currentHref}}}%
\makeatother
\usepackage{hyperref}

\begin{document}
\section{Heading One}
xxx

\begin{figure}
\end{figure}

\end{document}
  • So, localanchorname is like a fix for misplaced labels? – ebcontrol Oct 13 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.