7

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}
\addbibresource{biblatex-examples.bib}

\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}
1
  • natbib also provide this feature
    – ArTourter
    Commented Apr 5, 2017 at 11:07

1 Answer 1

6

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}
\addbibresource{biblatex-examples.bib}

\NewBibliographyString{refname}
\NewBibliographyString{refsname}
\DefineBibliographyStrings{english}{%
  refname = {ref\adddot},
  refsname = {refs\adddot}
}

\DeclareCiteCommand{\cite}
  {%
  \ifnum\thecitetotal=1
    \bibstring{refname}%
  \else%
    \bibstring{refsname}%
  \fi%
  \addspace\bibopenbracket%
  \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}

enter image description here

4
  • 2
    +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
    Commented Nov 1, 2017 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.
    – Janosh
    Commented Nov 1, 2017 at 18:10
  • 1
    @Casimir It's entirely up to you how you call this cite command, for example \DeclareCiteCommand{\ccite} or whatever you want. Commented Nov 1, 2017 at 18:15
  • @samcarter I know. Just wanted to mention it. This works great!
    – Janosh
    Commented Nov 1, 2017 at 18:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .