# refcheck and \nameref not getting along

Consider the following MWE

\documentclass[12pt]{article}
\usepackage[norefs]{refcheck}
\begin{document}
As we will see later (see \nameref{ans}), the answer is 42.
This simplifies to 42.
\end{document}


This typesets properly, but I get a warning that ans is never referenced. How can I get refcheck to realize that it was?

• refcheck manual says that it should be loaded after hyperref, but using it the other way round will make the error message to vanish – user31729 Mar 29 '16 at 15:06
• Unfortunately, the manual is right. Loading it the other way is equivalent to not loading refcheck at all, so it's not too surprising the error vanishes :) – Mark Mar 29 '16 at 15:13
• refcheck does a lot of redefinitions with the internal commands \ref etc. Perhaps this can be replicated for \nameref as well – user31729 Mar 29 '16 at 15:16
• See my updated answer please. – user31729 Mar 29 '16 at 15:19

Warning, this does not work for \nameref* so far...

refcheck redefines the usual \...ref commands like \ref, \pageref and \biblabel etc., and hooks into those commands, storing the argument to a list (of used label names) but it does not provide a similar approach for \nameref.

I assume, that \cref etc. from cleveref will fail as well then.

\documentclass[12pt]{article}
\usepackage[norefs]{refcheck}
\makeatletter
\AtBeginDocument{%
\let\@@nameref@@\nameref
\expandafter\DeclareRobustCommand\expandafter
{\csname relax\string\nameref\endcsname}[1]{\@@nameref@@{#1}\wrtusdrf{#1}}%
\expandafter\let\expandafter\nameref\csname relax\string\nameref\endcsname
}
\makeatother

\begin{document}
As we will see later (see \nameref{ans}), the answer is 42.

• @Mark: I had just a suspicion that refcheck would use a hooking approach for \label and \ref.... -- the rest was copying and adapting to \nameref ;-) – user31729 Mar 29 '16 at 15:51