# Is there a way of using something similar to natbib's \citenum in biblatex?

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? Jun 7, 2015 at 20:56
• @Bernard I use numeric-comp. Jun 7, 2015 at 21:08
• Isn't it the normal behaviour for citations commands? Jun 7, 2015 at 21:28
• @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{}]". Jun 7, 2015 at 22:37
• I see, I didn't get what you meant – I thought ypu obtained something more, such as the author. Jun 7, 2015 at 22:39

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}
%\ExecuteBibliographyOptions{labelnumber}

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

\begin{document}

\cite{article1}

\cite{article2}

\citenum{article1}

\citenum{article2}

\printbibliography

\end{document}


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}
%
\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}


• 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. Jun 7, 2015 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. Jun 7, 2015 at 23:34
• What do you mean by "all possible cases" here? Jun 7, 2015 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. Jun 7, 2015 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. Jun 7, 2015 at 23:55