[Tex/LaTex] Reverse numbering in biblatex bibliography with different categories

biblatexnumbering

I have different categories (filters) for entries in a bibliography using
biblatex (see below). I would like to add a numbering to the entries. Since the
entries are sorted by year in decreasing order, the numbering (in each category)
should also be decreasing.

Basically, I see two routes to go:

1) The first is to use style=numeric and a solution presented here.
However, in my (not so minimal) example, there appeared two problems. First, the
number does not start over again for each of the categories (instead, it
continues). Second, I obtained weird numbers (up to 400), although I only had a
couple of entries with the same keyword.

2) The second (probably easier) I found here. This is actually a nice idea (and lets you specify the numbering etc.), but I
couldn't figure out two things: First, how to get decreasing numbering. Second,
if you have > 9 entries, the space reserved for the label is too small and the
10th entry is not vertically aligned with the 9 before. This can probably be
adjusted with itemindent, but when I tried, the adjustments did not have an
effect.

\documentclass{scrartcl}

% packages
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[
backend=bibtex,
style=authoryear,% numeric,
sorting=ydnt% sort by year (descending), name, title
]{biblatex}

% create dummy .bib file
\usepackage{filecontents}
\begin{filecontents*}{mybib.bib}
@article{mykey1,
    author={I Me},
    journal={Journal of LaTeX questions},
    pages={1--10},
    title={My first LaTeX problem},
    volume={2},
    number={2},
    year={2011},
        keywords={published}}

@article{mykey2,
    author={I Me},
    journal={Journal of LaTeX questions},
    pages={1--10},
    title={My second LaTeX problem},
    volume={1},
    number={1},
    year={2012},
        keywords={submitted}}

@article{mykey3,
    author={I Me},
    journal={Journal of LaTeX questions},
    pages={1--10},
    title={My third LaTeX problem},
    volume={3},
    number={3},
    year={2013},
        keywords={submitted}}
\end{filecontents*}

% bibliography settings
\setlength{\bibhang}{1em}% separate bibitems by indentation
\defbibheading{submitted}{\large\sffamily Submitted}% heading
\defbibheading{published}{\large\sffamily Published}% heading
\defbibfilter{submitted}{keyword=submitted}% filter
\defbibfilter{published}{keyword=published}% filter
\addbibresource{mybib.bib}% bibliography data

% % Idea 1) 
% \AtDataInput{%
%   \csnumgdef{entrycount:\therefsection}{%
%     \csuse{entrycount:\therefsection}+1}}
% \DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}
% \newrobustcmd*{\mkbibdesc}[1]{%
%   \number\numexpr\csuse{entrycount:\therefsection}+1-#1\relax}

% Idea 2)
\defbibenvironment{bibliography}
{\enumerate{}
{\setlength{\leftmargin}{\bibhang}% => adjustments seem to have no effect
\setlength{\itemindent}{-\leftmargin}% => adjustments seem to have no effect
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}}}
{\endenumerate}
{\item}


\begin{document}
\section*{Publications}
\nocite{*}
\printbibliography[heading=submitted, filter=submitted]
\noindent\printbibliography[heading=published, filter=published]
\end{document}

Some more information

1) bibtex as backend is used here on purpose (so that texi2pdf runs biblatex automatically)

2) This problem comes from a CV. The idea is to use \nocite{*} (and not specific \cite{...}s so that I don't have to care about updating the references).

3) In the CV, I show categories "In preparation", "Submitted", "Published", "Book contributions", "Books". I use the following filtering to get this:

\defbibfilter{inpreparation}{type=article and keyword=inpreparation}
\defbibfilter{submitted}{type=article and keyword=submitted}
\defbibfilter{published}{type=article and keyword=published}
\defbibfilter{bookcontrib}{type=incollection and ( keyword=inpreparation or keyword=submitted or keyword=published )}
\defbibfilter{book}{type=book and ( keyword=inpreparation or keyword=submitted or keyword=published )}

Best Answer

The first solution mentioned doesn't work because your bibliography is split by keywords, not by reference sections. The general approach still applies provided that you make the counters keyword-specific.

\AtDataInput{%
  \csnumgdef{entrycount:\strfield{keywords}}{%
    \csuse{entrycount:\strfield{keywords}}+1}}

\DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}    
\newrobustcmd*{\mkbibdesc}[1]{%
  \number\numexpr\csuse{entrycount:\strfield{keywords}}+1-#1\relax}

This format has a few limitations:

  • It only applies to keyword filtering, not more general filters defined via \defbibfilter.
  • The item label width corresponds to \labelnumberwidth. This length is successively increased to accommodate the largest labelnumber based on all entries in the bbl file. So if the keywords filter out many entries, you may find the width too large.

If you don't intend to use the labelnumbers in citations (e.g. entries are accessed only via \nocite), then a simple solution to the above limitations is to patch \printbibligraphy. The following example demonstrates this approach. It also prints entries in the authoryear style.

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

\defbibfilter{primary}{type=article and keyword=primary}
\defbibfilter{secondary}{keyword=secondary}
\defbibfilter{other}{not type=article and not type=manual and not keyword=secondary}

\makeatletter
\patchcmd{\blx@printbibliography}
  {\blx@bibliography\blx@tempa}
  {\setcounter{bibitemtotal}{0}%
   \setlength{\labelnumberwidth}{0pt}%
   \begingroup
   \def\do##1{\stepcounter{bibitemtotal}}%
   \dolistloop{\blx@tempa}%
   \endgroup
   \blx@setlabwidth{\labelnumberwidth}{%
     \csuse{abx@ffd@*@labelnumberwidth}{\arabic{bibitemtotal}}}%
   \blx@bibliography\blx@tempa}{}{}
\makeatother

\newcounter{bibitemtotal}
\newrobustcmd*{\mkbibdesc}[1]{%
  \number\numexpr\value{bibitemtotal}+1-#1\relax}
\DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}
\DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{#1}}

\defbibenvironment{bibliography}
  {\list
     {\printtext[labelnumberwidth]{\printfield{labelnumber}}}
     {\setlength{\labelwidth}{\labelnumberwidth}%
      \setlength{\leftmargin}{\labelwidth}%
      \setlength{\labelsep}{\biblabelsep}%
      \addtolength{\leftmargin}{\labelsep}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}%
      \renewcommand*{\makelabel}[1]{\hss##1}}
  {\endlist}
  {\item}

\begin{filecontents}{\jobname.bib}
@article{glashow,
  author = {Glashow, Sheldon},
  title = {Partial Symmetries of Weak Interactions},
  journaltitle = {Nucl.~Phys.},
  volume = {22},
  date = {1961},
  pages = {579--588},
  keywords = {stdmodel,primary}}
@article{weinberg,
  author = {Weinberg, Steven},
  title = {A Model of Leptons},
  journaltitle = {Phys.~Rev.~Lett.},
  volume = {19},
  date = {1967},
  pages = {1264--1266},
  keywords = {stdmodel,primary}}
@inproceedings{salam,
  author = {Salam, Abdus},
  editor = {Svartholm, Nils},
  title = {Weak and Electromagnetic Interactions},
  booktitle = {Elementary particle theory},
  booktitleaddon = {Proceedings of the Eighth Nobel Symposium},
  location = {Stockholm},
  date = {1968},
  pages = {367--377},
  keywords = {primary,stdmodel}}
@book{augustine,
  author = {Augustine, Robert L.},
  title = {Heterogeneous catalysis for the synthetic chemist},
  publisher = {Marcel Dekker},
  location = {New York},
  date = {1995},
  keywords = {secondary}}
@book{kullback,
  title = {Information Theory and Statistics},
  author = {Kullback, Solomon},
  year = {1959},
  publisher = {John Wiley \& Sons},
  location = {New York}}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{oberdiek-bundle.bib}

\begin{document}
\nocite{*}
\printbibliography[filter=primary,title={Primary articles}]
\printbibliography[filter=secondary,title={Secondary works},resetnumbers]
\printbibliography[filter=other,title={Other works},resetnumbers]
\end{document}