# Visual feedback for broken hyperlinks and hypertargets

Is there a way to mark visually unused hypertargets and undefined hyperlinks. Of course I can check the log file, but I want to see critical links direct inside the pdf, e.g. by a different text colour.

I started to redefine hyperlink and hypertarget. At each call of one of this commands I create a variable that can be checked at the opposite command. This of course only works if the target is defined before the link reference it. But for the target it means the variable created by the associated hyperlink was not yet created, so for this hypertarget call it looks like it is not used. How can I solve this dilemma?

\documentclass{article}

\usepackage{color}
\usepackage{hyperref}

\ifcsname target@#1 \endcsname%
\else%
\fi
}

\newcommand{\myHypertarget}[2]{
\csname target@#1 \endcsname%
\hypertarget{#1}{#2}%
\else%
\hypertarget{#1}{\textcolor{blue}{#2}}%
\fi
}

\begin{document}
The first one brings me to \myHypertarget{t1}{here}, the second one \myHypertarget{t2}{here},
but the last one does not exist, in exchange an unused hypertarget is defined
\myHypertarget{t4}{here}.\\
\myHypertarget{t5}{Here} I define a hypertarget before the hyperlink, which
\end{document}

-

You can set-up dummy labels and test for their existence. Two runs are necessary for the color indicators or framed boxes to come to indicate truly the missing targets or links.

\documentclass{article}

\usepackage{xcolor}
\usepackage{hyperref}
\newcounter{susis}

\ifcsname r@susistarget#1\endcsname
\else
\fi
}

\newcommand{\myHypertarget}[2]{%
\refstepcounter{susis}\label{susistarget#1}%
\hypertarget{#1}{\textcolor{teal}{#2}}%
\else
\hypertarget{#1}{\fbox{\textcolor{red}{#2}}}%
\fi
}

\begin{document}