7

The natbib package provides the command \citenum, which returns just the number of the citation, unlike the typeset reference of \cite. Is a similar command available for biblatex?

  • Which style do you use? – Bernard Jun 7 '15 at 20:56
  • @Bernard I use numeric-comp. – Betohaku Jun 7 '15 at 21:08
  • Isn't it the normal behaviour for citations commands? – Bernard Jun 7 '15 at 21:28
  • 2
    @Bernard You mean the normal output in that style would be the number anyway? No, you get [1] instead of 1. This \citenum is useful if you want a style-independent output, for example "See Ref~[\citenum{}]". – Betohaku Jun 7 '15 at 22:37
  • I see, I didn't get what you meant – I thought ypu obtained something more, such as the author. – Bernard Jun 7 '15 at 22:39
6

Given that the numeric-comp style is used, it is possible to implement \citenum as follows:

\DeclareCiteCommand{\citenum}
  {}
  {\printfield{labelnumber}}
  {}
  {}

It can be use with other styles as well using the labelnumber package option.

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
  @article{article1,
    author = {Author, First},
    title  = {Title 1},
    year   = 1993,
    month  = may,
    pages  = {10--15}
  }

  @inproceedings{article2,
    author = {Author, Second},
    booktitle  = {Conference Title},
    title  = {Article 2},
    year   = 1975,
    month  = aug,
    pages  = {120--125}
  }
\end{filecontents}

\usepackage[style=authoryear,citecounter,natbib,labelnumber]{biblatex}
\addbibresource{\jobname.bib}
%\ExecuteBibliographyOptions{labelnumber}

\DeclareCiteCommand{\citenum}
  {}
  {\printfield{labelnumber}}
  {}
  {}

\begin{document}

\cite{article1}

\cite{article2}

\citenum{article1}

\citenum{article2}

\printbibliography  

\end{document}

enter image description here

1

To take into account every possible situation, I patched the original definition of the \cite command in numeric-comp.cbx:

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
  @article{article1,
    author = {Author, First},
    title = {Title 1},
    year = 1993,
    month = may,
    pages = {10--15}
  }

  @inproceedings{article2,
    author = {Author, Second},
    booktitle = {Conference Title},
    title = {Article 2},
    year = 1975,
    month = aug,
    pages = {120--125}
  }
\end{filecontents}

\usepackage[style=numeric-comp,citecounter,natbib,labelnumber]{biblatex}
\addbibresource{\jobname.bib}
%
\DeclareCiteCommand{\cite}%
  {\usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}%
   \usebibmacro{postnote}}

\begin{document}

\cite{article1}

\cite{article2}

\printbibliography

\end{document} 

enter image description here

  • 1
    This does give just the number, but destroys the flexibility of \cite itself. The goal would be to still be able to flexibly change the citation style for the \cite command and at the same time have a style-independent command such as \citenum that gives a clean number. – Betohaku Jun 7 '15 at 23:24
  • Nothing prevents you from calling the ‘patched’ command \citenum. What I meant was to take take into account all possible cases, just as the original \cite does. – Bernard Jun 7 '15 at 23:34
  • What do you mean by "all possible cases" here? – Betohaku Jun 7 '15 at 23:39
  • Well, I don't know exactly, because I do not have at hand afile with prenote and postnote, but you see the definition of the \cite command is not so simple. I suppose it is such for a good reason, and I preferred to stck as close as poss[ble to the original definition, which begins with \DeclareCiteCommand{\cite}[\mkbibbrackets], and decided to remove the [\mkbibbrackets] argument. It's the only modification. – Bernard Jun 7 '15 at 23:48
  • Now I wonder whether there are any situations in which the solutions of @Guido and you differ. I guess his solution will always just be a number, whereas yours might adjust in some way to the context. – Betohaku Jun 7 '15 at 23:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.