2

In the answers to this question, it is explained how "Ref." can automatically be added before any citation. However, I would like to have an automatic "Ref." or "Refs." depending on whether I \cite one reference or more than one reference, respectively. Is there any way to achieve this?

A simple example:

 \documentclass{report}
 \usepackage[latin1]{inputenc}
 \usepackage[T1]{fontenc}

 \begin{document}

 % This is what I would like to achieve without manually adding "Ref.~" and "Refs.~":
 This is a reference: Ref.~\cite{biba}
 These are two references: Refs.~\cite{biba,bibb}

 \begin{thebibliography}{}
 \bibitem{biba}
     Entry 1
 \bibitem{bibb}
     Entry 2
 \end{thebibliography}

 \end{document}

The output document reads:

This is a reference: Ref. [1] These are two references: Refs. [1,2]

I would like to achieve exactly this result, but without manually having to add "Ref.~" or "Refs.~" before every citation.

Ideally, I would prefer a solution without biblatex.

1
  • 1
    Welcome to TeX.SX! Can you add a compilable starter document please? Do you use natbib or any other non-biblatex package related to \cite?
    – user31729
    Commented Sep 7, 2015 at 15:38

1 Answer 1

2

Rather than to hack into the \cite and doing some transformations it's possible to count the , in the first argument to \cite

\documentclass{report}

\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{xstring}
\usepackage{letltxmacro}

\LetLtxMacro\origcite\cite
\renewcommand{\cite}[1]{%
\begingroup
\def\tempx{0}%
  \StrCount{#1}{,}[\tempx]%
  \ifnum\tempx > 0 
  Refs. %
  \else
  Ref. %
  \fi
\endgroup
\origcite{#1}%
}


\begin{document}

 This is a reference: \cite{biba}
 These are two references: \cite{biba,bibb}

 \begin{thebibliography}{}
 \bibitem{biba}
     Entry 1
 \bibitem{bibb}
     Entry 2
 \end{thebibliography}

 \end{document}

enter image description here

3
  • Basically works. However, I get a large space before every "Ref." (which can also be seen in your output)
    – el-barto
    Commented Sep 7, 2015 at 16:09
  • @el-barto Some more end-of-line % in the redefinition of \cite are required. Commented Sep 7, 2015 at 16:14
  • @el-barto: I was in a hurry, so I forgot some %. The white space should be gone now
    – user31729
    Commented Sep 7, 2015 at 16:45

You must log in to answer this question.

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