35

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.

3
  • 6
    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. Jun 22, 2011 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. Jun 22, 2011 at 20:53
  • 3
    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, 2011 at 19:49

1 Answer 1

34

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}

\addbibresource[label=biblatex]{biblatex-examples.bib}
\addbibresource[label=base]{xampl.bib}

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

enter image description here

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}{}{%
        \listcsxadd{entrylist:\therefsection}{\thefield{entrykey}}%
        \csnumgdef{entrycount:\therefsection}{%
          \csuse{entrycount:\therefsection}+1}}}
    
  • 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.

8
  • 1
    Excellent work! I will try it out and mark it correct if it works for me. I can't see why it wouldn't though. Thanks! Jul 11, 2011 at 15:00
  • Damn, spoke too soon. The problem is that I am doing this with three bibliographies, and this is usually the stumbling block. I will expand my question to include this point too. Jul 11, 2011 at 15:30
  • @Joel I've gone ahead and revised my answer. I think it should work for your case now.
    – Audrey
    Jul 12, 2011 at 1:17
  • 1
    Thanks @Audrey, I will check it out soon. Just as I was posting my edit to my answer (literally) the storm came through Chicago and my power has been out ever since. I appreciate your help, I normally am more responsive. Seeing as I am at my parents to check my email I will not delve into the deep LaTeX magic right now, still thanks for your help! Jul 13, 2011 at 1:44
  • and wow, thats cool about biber accessing github. I will def read more about that! Jul 13, 2011 at 1:46

You must log in to answer this question.

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