Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 )}
share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

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}
share|improve this answer
    
Thanks, Audrey. Unfortunately, it does not compile (Ubuntu 12.10, TeXLive 2012, texi2pdf). 1) Is it crucial to have biber as backend? I used bibtex (see Update), but I obtain output containing Database file #1: foo-blx.bib Database file #2: biblatex-examples.bib ... 2) The whole problem is part of a CV (see the update above). My fear with your solution (although I can't try) is that the numbering is relative to all \nocite{*} "entries" and not just counts the entries shown in the bibliography. I definitely wouldn't want having to \cite{} all entries by hand. –  Marius Hofert Feb 11 '13 at 7:10
    
Okay, let me try some things... I get back to you ... –  Marius Hofert Feb 11 '13 at 7:27
    
The problem is biblatex-examples.bib where texi2pdf exits abnormally. For my own .bib, compiling works well and the numbers are decreasing. However, they are still not correct, the reason being that my filters are of the form type=article and keyword=primary, not just keyword=primary (or even type=incollection and ( keyword=primary or keyword=secondary )). For example, you don't want to mix books and articles (=> filter different types as well). Because of this subsetting, some of the numbers are missing. Is there a solution to that? –  Marius Hofert Feb 11 '13 at 7:49
    
Another problem is the numeric style: How does one get the years printed as for the authoryear style (right after the authors' names)? –  Marius Hofert Feb 11 '13 at 8:29
    
@MariusHofert So you're filtering by type and keyword? Anything else? A solution relies on exactly how you're splitting the bibliographies. Without accurate information on this, I can't offer a solution. You should have no problem using BibTeX. You can also use \nocite{*}, but again if your bib file is large relative to the number of printed entries \labelnumberwidth is going to be too wide. There are ways around this, but I need more details on the filters. –  Audrey Feb 11 '13 at 14:22
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.