# biblatex: Reverse numbering (i.e., count down)

I was wondering if it is possible to get the citation numbers to count down

[3] newest item
[2] item
[1] oldest item


in biblatex? I am sorting using either using sorting=none and entering in reverse order or using sorting=ydnt and I would like the number of the newest (top) entry to be the highest and at the top of the list.

This is for the publications section of a CV.

If needed, a full example can be seen in my github repo for my CV, in the main.tex file.

-
Section 4.5.1 Sorting of the biblatex manual describes the use of the argument direction= with values (ascending or descending) for the \sort command. –  Gonzalo Medina Jun 22 '11 at 20:41
@Gonzalo, thanks for that. Now I know that it is at least possible. That would required defining a new sort scheme and also that I use biber as a backend. Not the worst case, but would involve some more effort. –  Joel Berger Jun 22 '11 at 20:53
I tried this, but it does not put the numbers in descending order - it simply puts the references in descending order by year (as could be accomplished by unsrt easily). Numbering the values in reverse is the trick needed. –  user6345 Jun 24 '11 at 19:49

The desired numbering scheme can be achieved by printing the labelnumber as the total number of entries in the current reference section, minus the actual label number, plus one.

This approach is demonstrated in the document below. It relies on commands from etoolbox and allows for an arbitrary number of reference sections.

\documentclass{article}
\usepackage[backend=bibtex,style=numeric,sorting=ydnt]{biblatex}

% Count total number of entries in each refsection
\AtDataInput{%
\csnumgdef{entrycount:\therefsection}{%
\csuse{entrycount:\therefsection}+1}}

% Print the labelnumber as the total number of entries in the
% current refsection, minus the actual labelnumber, plus one
\DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}
\newrobustcmd*{\mkbibdesc}[1]{%
\number\numexpr\csuse{entrycount:\therefsection}+1-#1\relax}

\begin{document}
\begin{refsection}[biblatex]
\nocite{markey,companion,ctan,knuth:ct}
\printbibliography[title={biblatex examples}]
\end{refsection}
\begin{refsection}[base]
\nocite{whole-set,inbook-minimal,book-minimal}
\printbibliography[title={Base examples}]
\end{refsection}
\end{document}


If the document is saved as doc.tex, compile with:

latex doc
bibtex doc1-blx
bibtex doc2-blx
latex doc


With backend=biber, there is no need to run biber on each of the reference sections. You can also access bib files remotely from github.

Some caveats:

• Shorthands. The labelnumber is overridden by the shorthand field. So with shorthands the maximum labelnumber in a given reference section doesn't correspond to the total number of cited entries. To handle this you can clear the shorthand field with biber by adding the following source map to the preamble:

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{\step[fieldset=shorthand,null]}
}
}

• Data-only entries. The code in \AtDataInput is executed for each entry in the bbl file. This includes related entries or other entries suppressed in the bibliography via skipbib or dataonly. To omit these from the entry total, you should condition on the skipbib setting.

\makeatletter
\def\ifskipbib{\iftoggle{blx@skipbib}}
\makeatother

\AtDataInput{\ifskipbib{}{%
\csnumgdef{entrycount:\therefsection}{\csuse{entrycount:\therefsection}+1}}}

• Multiple sorting schemes. If your document uses more than one sorting scheme in a reference section, the bbl file will contain duplicate entries - one for each scheme. To avoid counting duplicates, you can track the entries already counted in a list.

\AtDataInput{%
\xifinlistcs{\thefield{entrykey}}{entrylist:\therefsection}{}{%

• Multiple versus single bib files. Using a single bib file for each reference section is convenient, but not necessary - as long as the entries accessed in each section correspond to those printed in the bibliography. For an alternative approach with a single reference section and labelnumber prefixes, refer to this post.