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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

It seems that refcheck does not recognize references made by cleveref:

\documentclass{article}
\usepackage{amsmath}
\usepackage{cleveref}
\usepackage{refcheck}

\begin{document}
\begin{align}
  a & = b \label{eq:a} \\
  c & = d \label{eq:b}
\end{align}

See~\eqref{eq:a}, \cref{eq:b}.

\begin{figure}
  \caption{Figure 1}
  \label{fig:a}
\end{figure}
\begin{figure}
  \caption{Figure 2}
  \label{fig:b}
\end{figure}

See Figure~\ref{fig:a}, \cref{fig:b}.

\end{document}

Here, refcheck marks eq:b and fig:b as unreferenced.

  1. Is there a way to make the two packages work together?
  2. Alternatively, are there replacement packages that do work better?
  3. If the answer to 1) is yes, can this even be achieved for \crefrange?
share|improve this question
    
Have you tried "Poor man's cleveref" (chapter 10 in cleveref's docs)? This should be an easy workaround on a Linux or Mac OS X system. – krlmlr Dec 19 '12 at 23:19
1  
@user946850 I know that option, but I'm not convinced. As a purist, I don't want to run sed scripts in between. And you still have the false positives when using compressed references (\crefrange, and \cref with several labels). – mafp Dec 19 '12 at 23:40

refcheck doesn't know about \cref and \Cref. We can add a macro that makes the package aware of other reference commands:

\documentclass{article}
\usepackage{amsmath}
\usepackage{cleveref}
\usepackage{refcheck}

%%% Infrastructure    
\makeatletter
\newcommand{\refcheckize}[1]{%
  \expandafter\let\csname @@\string#1\endcsname#1%
  \expandafter\DeclareRobustCommand\csname relax\string#1\endcsname[1]{%
    \csname @@\string#1\endcsname{##1}\wrtusdrf{##1}}%
  \expandafter\let\expandafter#1\csname relax\string#1\endcsname
}
\makeatother
%%%

%%% Now we add the reference commands we want refcheck to be aware of
\refcheckize{\cref}
\refcheckize{\Cref}

\begin{document}
\begin{align}
  a & = b \label{eq:a} \\
  c & = d \label{eq:b}
\end{align}

See~\eqref{eq:a}, \cref{eq:b}.

\begin{figure}
  \caption{Figure 1}
  \label{fig:a}
\end{figure}
\begin{figure}
  \caption{Figure 2}
  \label{fig:b}
\end{figure}

See Figure~\ref{fig:a}, \Cref{fig:b}.

\end{document}

enter image description here

share|improve this answer
1  
This is great! But does it work when \creffing multiple labels? And what about \crefrange and friends? -- It seems that at least one of the packages should be enhanced to support the other, perhaps both: I imagine a command like \noref (provided by refcheck) that would simply mark a reference as "used" and could be called by cleveref, autoref, nameref, ... – krlmlr Dec 19 '12 at 23:06
1  
Nice. Unfortunately, I use \cref almost exclusively for multiple references to employ the compression feature, and in this case your solution obviously won't work. I guess one needs to hook deeper into the packages. Should I ask the cleveref author for active support of refcheck, or the refcheck author (I'm not sure if he is still an active Texie.)? – mafp Dec 19 '12 at 23:09
    
@user946850 refcheck simply modifies \ref and \pageref to write \usedref in the .aux file; the "refcheckized" macros do just the same. – egreg Dec 19 '12 at 23:09
1  
This also works with \autoref of hyperref. – WolframH Jul 21 '14 at 20:37
1  
@Mark Have you tried \refcheckize{\autopageref}? – egreg Mar 17 at 6:56

I ran into the same issue, and found it was relatively straightforward to extend egreg's answer to handle extra cases like \crefrange{eq1}{eq2} and \cref{eq1,eq2,eq4}:

\makeatletter
\newcommand{\refcheckize}[1]{%
  \expandafter\let\csname @@\string#1\endcsname#1%
  \expandafter\DeclareRobustCommand\csname relax\string#1\endcsname[1]{%
    \csname @@\string#1\endcsname{##1}\@for\@temp:=##1\do{\wrtusdrf{\@temp}}}%
  \expandafter\let\expandafter#1\csname relax\string#1\endcsname
}
\newcommand{\refcheckizetwo}[1]{%
  \expandafter\let\csname @@\string#1\endcsname#1%
  \expandafter\DeclareRobustCommand\csname relax\string#1\endcsname[2]{%
    \csname @@\string#1\endcsname{##1}{##2}\wrtusdrf{##1}\wrtusdrf{##2}}%
  \expandafter\let\expandafter#1\csname relax\string#1\endcsname
}
\makeatother

\refcheckize{\cref}
\refcheckize{\Cref}
\refcheckizetwo{\crefrange}
\refcheckizetwo{\Crefrange}

Credit goes to egreg for the original solution.

share|improve this answer
    
Works very well. However, the solution doesn't seem to like subfigures (using the subcaption package). – Alex Dec 25 '15 at 19:01

I ended up with using a little shell script to find unreferenced labels. This has some drawbacks of course, but works very well in my case (document with hundreds of pages):

# Helper function to find unreferenced labels, since the chkltex tool and the refcheck package do not support cleveref
# Note: this could show false positives sometimes
echo "Checking for unreferenced labels...";
labels=$(grep -Eo '^[\s]*[^%]+.*label{[^}]+}' $_dir_sources/*.tex|sed -Ee "s/^.*{(.*)}/\1/g")
for label in $labels; do
  found=$(grep -E "ref{[^}]*$label" $_dir_sources/*.tex)
  if [[ -z "$found" ]]; then
    echo "Label '$label' not referenced?";
  fi
done
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.
http://tex.stackexchange.com/questions/87610/making-refcheck-work-with-cleveref
tex.stackexchange.com
crawl=CC-MAIN-2016-18
90905
application/http; msgtype=response
sha1:LTJGIPIUCDAMM6LYZWG4VRIGISMCXCZ3
<urn:uuid:bce89d22-097a-4eb3-8c6a-647532a93c03>
2016-04-29T23:40:38Z
104.16.118.182
sha1:GI7GFWQUJDJ25WJJXFQMDMTWNKOFG22H
<urn:uuid:5980442d-3b4c-4500-aebe-d73db8be69f0>
http://tex.stackexchange.com/questions/87610/making-refcheck-work-with-cleveref
response
<urn:uuid:fa597bb4-fd8d-4f77-a26a-6e5ce455beb0>
robots: classic
hostname: ip-10-239-7-51.ec2.internal
software: Nutch 1.6 (CC)/CC WarcExport 1.0
isPartOf: CC-MAIN-2016-18
operator: CommonCrawl Admin
description: Wide crawl of the web for April 2016
publisher: CommonCrawl
format: WARC File Format 1.0
conformsTo: http://bibnum.bnf.fr/WARC/WARC_ISO_28500_version1_latestdraft.pdf