Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is there a way to force LaTeX to automatically change the formatting of the ?? that gets typeset in place of an undefined reference? For example, can one make LaTeX draw a yellow "highlight" background behind the ??, or render the ?? in red text?

I would like it to be easier to spot these undefined references when skim reading PDF output.

An MWE would be

\documentclass{article}
\begin{document}
\ref{undefinedReference}
\end{document}

It would be especially great if this could be made to work for undefined bibliographic citations as well as undefined cross refs.

share|improve this question
2  
Missing references are noted in the log file and produce a warning. A good start is to keep on eye on what LaTeX tells you there. –  Andrew Swann May 9 at 14:26

2 Answers 2

up vote 7 down vote accepted

I don't think you will miss this:

\documentclass{article}
\usepackage{color}
\makeatletter

\def\@setref#1#2#3{%
  \ifx#1\relax
   \protect\G@refundefinedtrue
   \nfss@text{\reset@font\bfseries\huge\textcolor{red}{DEFINE #3 NOW, AND MAKE IT QUICK!}}%
   \@latex@warning{Reference `#3' on page \thepage \space
             undefined}%
  \else
   \expandafter#2#1\null
  \fi}

\makeatother
\begin{document}
\ref{undefinedReference}
\end{document}
share|improve this answer
1  
A macro that makes the machine punch you in the eye would be missed more frequently than this one. –  egreg May 9 at 15:15
    
Thanks David Carlisle. I used \nfss@text{\reset@font\colorbox{yellow}{??$_\text{#3}$}} and put the whole thing into a .sty file to make a package that I can invoke to achieve this functionality on all my manuscripts. –  Ubiquitous May 9 at 15:46
1  
@Ubiquitous I'd prefer the version that punched egreg in the eye, but OK:-) –  David Carlisle May 9 at 16:04

Based on David's answer, here's a solution with PDF annotations as 'yellow "highlight" background':

\documentclass{article}
\usepackage[rgb]{xcolor}
\usepackage{pdfcomment}
\makeatletter

\def\@setref#1#2#3{%
  \ifx#1\relax
   \protect\G@refundefinedtrue
   \nfss@text{\reset@font\bfseries\pdfmarkupcomment[color=yellow,author={RefCheck Assistant}]{??}{DEFINE #3 NOW, AND MAKE IT QUICK!}}%
   \@latex@warning{Reference `#3' on page \thepage \space
             undefined}%
  \else
   \expandafter#2#1\null
  \fi}

\makeatother
\begin{document}
see \ref{undefinedReference}
\end{document}

enter image description here

without clicking and mouseover you get a tooltip:

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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