2

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.

6

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

enter image description here

\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%
      \advance\leftmargin\labelsep}%
      \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}

\addbibresource{biblatex-examples.bib}
\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%
      \advance\leftmargin\labelsep}%
      \sloppy\clubpenalty4000\widowpenalty4000}
  {\endlist}
  {\item}
\makeatother

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

\addbibresource{biblatex-examples.bib}
\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.

| improve this answer | |
  • 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. – mbarete 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[..] ... – Werner 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. – mbarete Mar 27 '15 at 0:26
  • @mbarete: I've added my \citesinthissection suggestion. – Werner Apr 2 '15 at 4:53
  • I improved the code for multiple bibliography. The previous one didn't really work. – giordano Nov 1 '16 at 22:44

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.