Show reference label when it is undefined

The definition of \cite calls an internal \@citex that checks the citation and adds an \hbox{\reset@font\bfseries ?} for undefined citations. Changing it to call the argument to \cite instead of the question mark works fine.

\makeatletter
% latex.ltx, line 6121:
\def\@citex[#1]#2{\leavevmode
  \let\@citea\@empty
  \@cite{\@for\@citeb:=#2\do
    {\@citea\def\@citea{,\penalty\@m\ }%
     \edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
     \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
     \@ifundefined{b@\@citeb}{\hbox{\reset@font\bfseries 
     \expandafter\strip@prefix\meaning\@citeb}%
       \G@refundefinedtrue
       \@latex@warning
         {Citation `\@citeb' on page \thepage \space undefined}}%
       {\@cite@ofmt{\csname b@\@citeb\endcsname}}}}{#1}}
\makeatother

A much cleaner way to redefine \@citex is by patching it with xpatch:

\usepackage{xpatch}
\makeatletter
\xpatchcmd{\@citex}{\bfseries ?}{\bfseries\expandafter\strip@prefix\meaning\@citeb}{}{}
\makeatother

MWE:

\documentclass{article}
% \usepackage{lmodern}
\usepackage[T1]{fontenc}
\makeatletter
% latex.ltx, line 6121:
\def\@citex[#1]#2{\leavevmode
  \let\@citea\@empty
  \@cite{\@for\@citeb:=#2\do
    {\@citea\def\@citea{,\penalty\@m\ }%
     \edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
     \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
     \@ifundefined{b@\@citeb}{\hbox{\reset@font\bfseries 
     \expandafter\strip@prefix\meaning\@citeb}%
       \G@refundefinedtrue
       \@latex@warning
         {Citation `\@citeb' on page \thepage \space undefined}}%
       {\@cite@ofmt{\csname b@\@citeb\endcsname}}}}{#1}}
\makeatother
\begin{document}
\null\vfill\thispagestyle{empty}

This: \cite{undef} should look like: [{\bfseries ?? undef}]

This one \cite{article-minimal} shouldn't.

Ugly citation keys with special chars like \cite{_$^/:&!@*(-=+)} 
also should be printed.

\bibliography{xampl.bib}
\bibliographystyle{plain}
\end{document}

enter image description here

This answer is sponsored by texdef and (very!) special comments by tohecz and Gonzalo Medina :)


biblatex provides this functionality by default:

enter image description here

\documentclass{article}
\usepackage{biblatex}% http://ctan.org/pkg/biblatex
\begin{document}
See~\cite{author}.
\end{document}