# Replace unknown reference (?) with the tag from \ref or \cite

While working on a document, it would be helpful if instead of a ? for unresolved references or citations the tag used in the \ref{thisthings} or \cite{Bloke1978} could appear instead.

Is there a package that turns on this behaviour?

-

Rather than redefining \cite or connected commands, one might consider using the showkeys package, that will print every key and mark every usage of \label so that, during document preparation, cross-references can be checked quite easily.

This has a drawback: line and page break can be different when using or not using the package. However, line and page break are not much of a concern when we are writing our manuscript. When finalizing the project just comment out the call to showkeys: the cross-references should be OK, at that point.

-
That is a more useful solution than just replacing the unresolved labels. Thanks! –  Alex Feb 18 '12 at 22:46

Even if there is no such package, it's easy to modify the corresponding commands with the help of the etoolbox package. This may, however, fail if some package redefines the commands in an incompatible way.

\documentclass{article}

\usepackage{etoolbox}

\makeatletter
\patchcmd{\@setref}{\bfseries ??}{[\texttt{#3}]}{}{%
\GenericWarning{}{Failed to patch \protect\@setref}}
\patchcmd{\@citex}{\bfseries ?}{\texttt{\@citeb}}{}{%
\GenericWarning{}{Failed to patch \protect\@citex}}
\makeatother

\begin{document}

\ref{undefined},\pageref{undefined},\cite{undefined}

\end{document}

-
One might also consider the showkeys package. –  egreg Feb 18 '12 at 11:16
@egreg: That's cool! Your comment should be an answer. –  Andrey Vihrov Feb 18 '12 at 11:18