[Tex/LaTex] Journal class shows ‘Package hyperref Warning: Suppressing link with empty target on input line XXX’

document-classeshyperreftemplateswarnings

Compiling the following example file:

\documentclass{aa}
\usepackage{hyperref}
\begin{document}
\section{Introduction}
Aaaa bbbb~\cite{Smith_2005} cccc.
\bibliographystyle{aa}
\bibliography{biblio}
\end{document}

shows the warning:

…/test.tex:15: Package hyperref Warning: Suppressing link with empty target on input line 15.

I compile with:

$ latexmk test.tex

my LaTeX version is:

$ latex
This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian) (preloaded format=latex)

The biblio.bib file looks like this:

@ARTICLE{Smith_2005,
    author = {{Smith}, N.~V.},
    journal = {AAA},
    year = 2005,
    month = sep,
    volume = 440,
    pages = {403-408},
}

and the other two files needed to compile are here: aa.cls, aa.bst.

Disabling the hyperref package makes the warning go away, but I need it to be enabled. The final PDF looks fine, but I wonder why this warning appears since I don't remember seeing it before.

Best Answer

The class stores the last page number as a reference using LastPage, written as part of \end{document} (comment added):

\renewcommand*\enddocument{%
   \let\AtEndDocument\@firstofone
   \@enddocumenthook
   \clearpage
   \advance\c@page \m@ne
   \immediate\write\@auxout{\string\newlabel{LastPage}{{\thepage}{\thepage}{}{}{}}}
   % ^^^^ This writes the (last) page number as a \label to the .aux
   \@checkend{document}%
   \clearpage
   \begingroup
     \if@filesw
       \immediate\closeout\@mainaux
       \let\@setckpt\@gobbletwo
       \let\@newl@bel\@testdef
       \@tempswafalse
       \makeatletter \input\jobname.aux
     \fi
     \@dofilelist
     \ifdim \font@submax >\fontsubfuzz\relax
       \@font@warning{Size substitutions with differences\MessageBreak
                  up to \font@submax\space have occurred.\@gobbletwo}%
     \fi
     \@defaultsubs
     \@refundefined
     \if@filesw
       \ifx \@multiplelabels \relax
         \if@tempswa
           \@latex@warning@no@line{Label(s) may have changed.
               Rerun to get cross-references right}%
         \fi
       \else
         \@multiplelabels
       \fi
     \fi
   \endgroup
   \deadcycles\z@\@@end}

Note that the \newlabel is written with 5 arguments. However, arguments 3, 4 and 5 are empty. This is to accommodate regular, non-hyperref \labels which only require two arguments, as well as when hyperref is loaded (which writes \labels with 5 arguments).

This LastPage reference is used in the footer throughout the document via this macro (line 425):

\newcommand*\aa@pageof{, page \thepage{} of \pageref{LastPage}}

While this works in general, hyperref uses the additional arguments (empty in this case) to identify markers for the last page as a hyperlink/jump. Since they're empty, hyperref ignores the hyperlink and merely prints the (page) reference (together with a warning).

You can avoid this warning by changing the \pageref to \pageref*; add the following to your preamble:

\makeatletter
\renewcommand*\aa@pageof{, page \thepage{} of \pageref*{LastPage}}
\makeatother

Alternately, make all \pagerefs default to hyperlink-less references:

\let\oldpageref\pageref
\renewcommand{\pageref}{\oldpageref*}