I am using the hyperref package. My .tex file contains some automatically generated content that uses \hyperlink to refer to content often not included in the .tex file. Its hard to find where these occur, since these hyperlinks are introduced by macros. Is it possible to highlight such broken references in bright in the PDF itself?

Here is a concrete minimal example:


\hypertarget{correctDest}{This can be used as a destination of some hyperlink}
The line below has 2 hyperlinks, one to the above destination
and another to an undefined destination.\\
Clicking \hyperlink{correctDest}{here} should be good.
Clicking \hyperlink{undefined}{here} is bad because
there is no destination in this document that defined the
destination undefined. Is there a way that the latter hyperlink
is highlighted in the PDF so that it is easy to find and fix them?

The error message I get does not even tell me the line number where broken reference is present

pdfTeX warning (dest): name{undefined} has been referenced but does not exist,    
replaced by a fixed one
  • 1
    Without a minimal example of code, it's impossible to give any advice. – egreg Mar 19 '15 at 18:52
  • @egreg : Thanks. I just did that. Please let me know if I should improve the question even further. – Abhishek Anand Mar 19 '15 at 23:15
  • 2
    pdftex issues the warning when it's finishing the process. A target for undefined might appear much later than the corresponding \hyperlink command. Such internal references are directly managed by pdftex so there's no entry in the .aux file and this processing is independent of actual typesetting. – egreg Mar 19 '15 at 23:31

Because we are not sure that the text

pdfTeX warning (dest): name{undefined} has been referenced

is unbroken to more lines, the usage of grep is more complicated. Maybe this checking can be implemented more simple at macro level. For example, when we are using plain TeX with OPmac then the code sould be:

\input opmac

   \expandafter\ifx\csname islink:#1\endcsname\relax {\localcolor\Red #3}%
   \else \linkactive[#1]{\localcolor\Blue}{#3}\fi

%% Testing:    


Clicking \hyperlink[correctDest]{here} should be good.
Clicking \hyperlink[undefined]{here} is bad because there is no destination
in this document.


OPmac uses the working REF file \jobname.ref where all data needed to be read again are accumulated. This is similar like aux, but there is only this file, no more (no toc etc.). The \dest[mark] macro prints the \sdef{isindent:mark}{} to the REF file and the \link macro can ask, if this control sequence is defined. If this is true then normal \linkactive is processed else only text is printed in \Red color.

Sorry, I will not rewrite this idea for LaTeX and hyperref package, because I am not supporting LaTeX. I refuse to dig in 8803 lines of hyperref.sty code while there are only 44 simple lines in OPmac which solve mostly the same problematic (hyperlinks). But you can be inspired by this and try to implement this for the macro package you are using.

  • 1
    I, too, pull out the necklace of garlic when confronted with hyperref. – Steven B. Segletes Apr 29 '15 at 11:43

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.