2

I use the package cleveref to produce cross-references like "Figure 4" instead of just "4", with the word "Figure" clickable as well. However, cleveref doesn't create citation call-outs.

I wonder how can I have something like \cite{einstein} produce "Reference 1" instead of "1", with the word "Reference" clickable as well. Thank you for your help.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage[style=nejm, backend=biber]{biblatex}
\addbibresource{sample.bib}

\begin{document}
Let's cite! The Einstein's journal paper \cite{einstein} and the Dirac's 
book \cite{dirac} are physics related items. 

\printbibliography

\end{document}

The bibliography file (sample.bib):

@article{einstein,
    author =       "Albert Einstein",
    title =        "{Zur Elektrodynamik bewegter K{\"o}rper}. ({German})
    [{On} the electrodynamics of moving bodies]",
    journal =      "Annalen der Physik",
    volume =       "322",
    number =       "10",
    pages =        "891--921",
    year =         "1905",
    DOI =          "http://dx.doi.org/10.1002/andp.19053221004",
    keywords =     "physics"
}

@book{dirac,
    title={The Principles of Quantum Mechanics},
    author={Paul Adrien Maurice Dirac},
    isbn={9780198520115},
    series={International series of monographs on physics},
    year={1981},
    publisher={Clarendon Press},
    keywords = {physics}
}

1 Answer 1

1

biblatex-nejm is based on numeric-comp. numeric-comp is quite complicated to modify, so we need quite a bit of code.

The idea is to add Reference\addspace before all \printfield{labelprefix}\printfield{labelnumber} blocks.

\documentclass[12pt,twoside]{article}
\usepackage[spanish,es-noquoting]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} 
\usepackage{hyperref}
\usepackage[style=nejm, backend=biber]{biblatex}

\addbibresource{biblatex-examples.bib}

\makeatletter
\renewbibmacro*{cite:comp:comp}{%
  \ifboolexpr{
    ( test {\iffieldundef{labelprefix}} and test {\ifundef\cbx@lastprefix} )
    or
    test {\iffieldequals{labelprefix}{\cbx@lastprefix}}
  }
    {\ifnumequal{\thefield{labelnumber}}{\value{cbx@tempcntb}}
       {\savefield{entrykey}{\cbx@lastkey}%
        \savefield{labelnumber}{\cbx@lastnumber}%
        \addtocounter{cbx@tempcnta}{1}}
       {\ifnumequal{\thefield{labelnumber}}{\value{cbx@tempcntb}-1}
          {}
          {\usebibmacro{cite:dump}%
           \ifnumgreater{\value{cbx@tempcntb}}{-1}
             {\multicitedelim}
             {}%
           \printtext[bibhyperref]{%
             Reference\addspace
             \printfield{labelprefix}%
             \printfield{labelnumber}}}}}
    {\usebibmacro{cite:comp:end}}%
  \setcounter{cbx@tempcntb}{\thefield{labelnumber}}%
  \savefield{labelprefix}{\cbx@lastprefix}}

\renewbibmacro*{cite:comp:end}{%
  \usebibmacro{cite:dump}%
  \ifnumgreater{\value{cbx@tempcntb}}{-1}
    {\multicitedelim}
    {}%
  \printtext[bibhyperref]{%
    Reference\addspace
    \printfield{labelprefix}%
    \printfield{labelnumber}}}

\renewbibmacro*{cite:dump}{%
  \ifnumgreater{\value{cbx@tempcnta}}{0}
    {\ifnumgreater{\value{cbx@tempcnta}}{1}
       {\bibrangedash}
       {\multicitedelim}%
     \bibhyperref[\cbx@lastkey]{%
       Reference\addspace
       \ifdef\cbx@lastprefix
         {\printtext[labelprefix]{\cbx@lastprefix}}
         {}%
       \printtext[labelnumber]{\cbx@lastnumber}}}
    {}%
  \setcounter{cbx@tempcnta}{0}%
  \global\undef\cbx@lastprefix}
\makeatother

\begin{document}
In particular we can cite \cite{sigfridsson} but could also be \cite{geer} or anything \cite{sigfridsson,nussbaum,geer}.

In particular we can cite \cite{sigfridsson} but could also be \cite{nussbaum} or anything.

In particular we can cite \cite{worman} but could also be \cite{geer} or anything \cite{sigfridsson,nussbaum,geer,knuth:ct:a}.

\printbibliography
\end{document}

enter image description here

3
  • Thank you ! I still have two questions: - How to get ride of "tex:0 Macro 'cite:dump' already defined" ? - Where did you found how to do that ?
    – Nakrule
    Oct 18, 2017 at 11:28
  • 1
    @Nakrule Issue one should be addressed with the edit. And re your second question: Experience, you only have to follow the macros through the different files until you find the one you have to modify.
    – moewe
    Oct 18, 2017 at 11:32
  • Thank you, I don't have any warnings left !
    – Nakrule
    Oct 18, 2017 at 11:34

You must log in to answer this question.

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