6

I would like to have all the broken links in a document come out purple when I compile, and the working links come out whatever color I've set internal links to.

For example, in the following document's output

\documentclass{article}
\usepackage{amsthm,hyperref}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}\label{catfish}
\end{theorem}
Theorem \ref{catfish} implies the truth of Conjecture \ref{god}.
\end{document}

I would like the working reference to not be purple, and the broken one, rendered as ??, to be purple. Is there a reasonable way to do it? (I am sorry if the question was inherently bad or if it was unclear before.)

P.S.: It might also be useful to compile a list of broken links. How might I do that?

Thank you.

jdc
  • 1,245

1 Answers1

6
\documentclass{article}
\usepackage{etoolbox}
\usepackage{xcolor}
\tracingpatches
\usepackage{amsthm,hyperref}
\newtheorem{theorem}{Theorem}
\makeatletter
\patchcmd{\@setref}{\bfseries ??}{\bfseries\color{red} undefined Label}{}{}
\makeatother
\begin{document}
\begin{theorem}\label{catfish}
\end{theorem}
Theorem \ref{catfish} implies the truth of Conjecture \ref{god}.
\end{document}

undefinedLabel

Johannes_B
  • 24,235
  • 10
  • 93
  • 248
  • P.S.: Is there a way to modify this so that it also does this for broken citations, e.g., \cite[p.~666]{ThingNotInMyBibFile}? – jdc Jan 23 '15 at 02:24
  • 1
    @jdc Depends on how you are citing. biblatex (recommended) behaves different from all the older methods. Please open a new question for that (you can crosslink to keep them somehow related). – Johannes_B Jan 23 '15 at 08:36