# Clever cite command

cleveref's \cref command is great for automatically adding prefixes like fig(s)., section(s), eq(s). etc. to cross-references. Unfortunately, it doesn't (natively) offer this functionality for citations?

What I'm looking for is a command \ccite that behaves as follows:

• \ccite{ref1} - "ref.~[1]"
• \ccite{ref1,ref5,ref11} - "refs.~[1,5,11]"

Can biblatex be used to implement this? Or can cleveref be extended to support citations? If not, is there another package that offers this functionality which is compatible with both biblatex and cleveref? Here's an MWE:

\documentclass{article}

\usepackage{hyperref,cleveref}

\usepackage[backend=biber,sorting=none,citestyle=numeric-comp]{biblatex}

\begin{document}

Early on, Herrmann showed in ref.~\cite{herrmann} that grass is green.

A collaborative research effort was later able to demonstrate in  refs.~\cite{bertram,doody,gillies,glashow} that the sky is blue.

\printbibliography

\end{document}

• natbib also provide this feature – ArTourter Apr 5 '17 at 11:07

You could change the \cite command or create a new command that automatically adds "ref." or "refs.":

\documentclass{article}

\usepackage{hyperref,cleveref}

\usepackage[backend=biber,sorting=none,citestyle=numeric-comp]{biblatex}

\NewBibliographyString{refname}
\NewBibliographyString{refsname}
\DefineBibliographyStrings{english}{%
}

\DeclareCiteCommand{\cite}
{%
\ifnum\thecitetotal=1
\bibstring{refname}%
\else%
\bibstring{refsname}%
\fi%
\usebibmacro{cite:init}%
\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{cite:comp}}
{}
{\usebibmacro{cite:dump}%
\usebibmacro{postnote}%
\bibclosebracket}

\renewrobustcmd*{\Cite}{\bibsentence\cite}

\begin{document}

In sentence \cite{herrmann}.

In sentence \cite{bertram,doody,gillies,glashow}.

\Cite{herrmann} at start of sentence.

\Cite{bertram,doody,gillies,glashow} at start of sentence.

\printbibliography

\end{document}


• +1) Just one tiny thing: I'd use refname = {ref\adddot}, instead of refname = {ref.},. That tells biblatex that the dot is an abbreviation dot and not a full stop. – moewe Nov 1 '17 at 18:09
• I only want to change some citations to include the prefix. Most should remain as they are (which is why I suggested a new custom cite command). I like the fine-grain control cleveref offers with \cref and \labelcref and was hoping for the same with citations. – Casimir Nov 1 '17 at 18:10
• @Casimir It's entirely up to you how you call this cite command, for example \DeclareCiteCommand{\ccite} or whatever you want. – user36296 Nov 1 '17 at 18:15
• @samcarter I know. Just wanted to mention it. This works great! – Casimir Nov 1 '17 at 18:16