# Reverse Numbering with Biblatex and Moderncv

This question is a follow-up to an earlier question. I'm using ModernCV with Biblatex to make my CV. I've used the solution given to create a list of publications, sorted by type and by year.

My question is how I can reverse the numbering of the publications (highest first) without changing anything else. Solutions exist for how to do this from multiple .bib files and I may consider that option if this is impossible, but an option where I could continue using a single bib file would be ideal.

If you just wish to reverse the numbering - not the order - then you can use the following approach:

\documentclass{moderncv}
\usepackage{biblatex,refcount}

\makeatletter
% https://tex.stackexchange.com/q/66829/5764
\newcounter{numbibentries}
\renewbibmacro*{finentry}{\stepcounter{numbibentries}\finentry}
% https://tex.stackexchange.com/q/123805/5764
\defbibenvironment{bibliography}
{\list
{\printtext[labelnumberwidth]{% label format from numeric.bbx
\printfield{prefixnumber}%
\number\numexpr\getrefnumber{num-bib-entries}-\abx@field@labelnumber+1\relax}}
{\setlength{\topsep}{0pt}% layout parameters from moderncvstyleclassic.sty
\setlength{\labelwidth}{\hintscolumnwidth}%
\setlength{\labelsep}{\separatorcolumnwidth}%
\leftmargin\labelwidth%
\sloppy\clubpenalty4000\widowpenalty4000}
{\endlist}
{\item}
\AtEndDocument{% Add reference at end of document to remember number of bib-entries.
\edef\@currentlabel{\thenumbibentries}\label{num-bib-entries}}
\makeatother

\moderncvstyle{classic}
\moderncvcolor{blue}
\firstname{John}
\familyname{Doe}

\begin{document}
\makecvtitle
\nocite{companion,knuth:ct:a,knuth:ct:b}
\printbibliography[title={Publications}]
\end{document}


The idea is to count the number of references by tapping into each "\bibitem". Once all is counted, we insert a \label at the end of the document (using \AtEndDocument). This label is retrieved and used in a calculation (thanks to the expandable \getrefnumber from refcount) to reverse the numbering.

For multiple bibliographies per document, you could use \citesinthissection{<num>} as defined below:

\documentclass{moderncv}
\usepackage[defernumbers=true]{biblatex}

\makeatletter
\newcommand{\citesinthissection}[1]{\xdef\@totalcites{#1}}
% https://tex.stackexchange.com/q/123805/5764
\defbibenvironment{bibliography}
{\list
{\printtext[labelnumberwidth]{% label format from numeric.bbx
\printfield{prefixnumber}%
\number\numexpr\@totalcites-\abx@field@labelnumber+1\relax}}
{\setlength{\topsep}{0pt}% layout parameters from moderncvstyleclassic.sty
\setlength{\labelwidth}{\hintscolumnwidth}%
\setlength{\labelsep}{\separatorcolumnwidth}%
\leftmargin\labelwidth%
\sloppy\clubpenalty4000\widowpenalty4000}
{\endlist}
{\item}
\makeatother

\moderncvstyle{classic}
\moderncvcolor{blue}
\firstname{John}
\familyname{Doe}

\begin{document}
\makecvtitle
\nocite{companion,knuth:ct:a,knuth:ct:b}
\citesinthissection{3}% There are 3 cites in this section
\printbibliography[notkeyword=primary,title={Publications}]
\nocite{aristotle:anima,aristotle:physics}
\citesinthissection{2}% There are 2 cites in this section
\printbibliography[keyword=primary,resetnumbers=true,title={Other Publications}]
\end{document}


Remember to update the count of items whenever you add elements to your bibliography. Use the defernumbers=true global option and resetnumbers=true option from the second \printbibliography onwards. You may need to use options like keyword/notkeyword options in order to print exactly only what you want in each bibliography part.

• This answer works well. However, I have multiple categories (say inproceedings and article). I can use something like '\printbibliography[type=article,heading=subbibliography,title={Journal Articles}]' to print each section separately. However, I'd like to be able to reset the counter for each section. If I use the additional option ',resetnumbers=true' then each section's numbering begins at N, where N is the number of references across all sections, rather than the number of references in the particular subsection. Mar 26 '15 at 17:34
• @mbarete: I see. An easy fix here would be to remove my automated approach and introduce some manual insertions. For example, if you know how many references you'll have in each section, one can precede a \printbibliography with something like \citesinthissection. That is, \citesinthissection{4} \printbibliography[..] ... \citesinthissection{7} \printbibliography[..] ... Mar 26 '15 at 18:20
• Is there a way to combine this solution tex.stackexchange.com/questions/43476/… with the formatting for moderncv? If not then continuous numbering is a second-best fit. Mar 27 '15 at 0:26
• @mbarete: I've added my \citesinthissection suggestion. Apr 2 '15 at 4:53
• I improved the code for multiple bibliography. The previous one didn't really work. Nov 1 '16 at 22:44