# How to sort reference list depending on the number of authors with Biblatex?

The guidelines of my papers have specific requirements of how to sort the reference list, which depends on the alphabetical order of the authors, the year of publication and additionally the number of authers. I struggle with the ordering by numbers of authors.

These are the rules:

1. Authors have to be presented in alphabetical order (ascending)
2. If one author has several publications, they have to be ordered by the year of publication (ascending).
3. If an author has written papers with varying numbers of co-authors, the references have to appear in ascending order of the number of co-authors: All papers with two co-authors, all papers with three co-authors, ...

So for example, this would be the appropriate order:

Author, A (2010) ...

Author, A, Cuthor, C (2005) ...

Author, A, Duthor, D (1990) ...

Author, A, Duthor, D (2000) ...

Author, A, Buthor, B, Cuther, C (2000) ...

and so on. I struggle with the ordering based on the numbers of authors. I am using latest version of Biblatex with author/year citation style - Is there a way to achieve the appropriate reference list?

• Somewhere there must be a ministry of silly rules for reference lists. With a numeric citation style it would be at least usable, but with an author/year style it only makes for the reader more difficult to find an entry. So where is the sense? Nov 2, 2016 at 11:47
• Making sense or not - I have to comply with the given rules for structuring the reference list. Therefore I would appreciate any tips on how to achieve the correct order :)
– DrA
Nov 2, 2016 at 14:51
• Well you could bribe me: Ask someone who made this rule (or inforce it now) to explain publicly why he/she thinks it is of any use to put "Adam and Zenon" before "Adam, Adam and Aurelius" and that he/she really wants you to comply to this rule. I would like to know who to blame ... Nov 2, 2016 at 18:10
• I think the logic is: A did this and that in year X, here are the things he/she did alone, and here is what he/she did with others. Then we switch to year X+1. It happened to me, in a bibliography, to have A+B for one page, from 1990 to 2020, and then to switch to A+C again from 1990, not optimal… Sep 27, 2020 at 16:50

Satisfying this (silly) sorting scheme requires using some advanced features. You should use a custom field to sort by and use a source map to populate the field with a construction functionally determined by the number of authors. What we are doing here is effectively calculating the number of ands in the author name list which, due to the BibTeX name format, is a count of the names. So, a concatenation of the ands is a string which can be used to sort the entries. Then, a custom sorting scheme sorts on this field before alphabetical name sort:

\documentclass{article}
\usepackage{csquotes}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{AuthorA2010,
title={Titlea},
author={Author, Alan},
journal={Journala},
volume={10},
pages={1--3},
year={2010},
publisher={Publishera}
}
@article{AuthorAC2005,
title={Titleac},
author={Author, Alan and Cuthor, Carla},
journal={Journalac},
volume={10},
pages={1--3},
year={2005},
publisher={Publisherac}
}
author={Author, Alan and Duthor, David},
volume={10},
pages={1--3},
year={1990},
}
author={Author, Alan and Duthor, David},
volume={10},
pages={1--3},
year={2000},
}
@article{AuthorABD2000,
title={Titleabd},
author={Author, Alan and Bill Buthor and Cuthor, Carla},
journal={Journalabd},
volume={10},
pages={1--3},
year={2000},
publisher={Publisherabd}
}
\end{filecontents}
\usepackage[style=authoryear,firstinits=true, dashed=false,sorting=custsort]{biblatex}
\DeclareSortingScheme{custsort}{
\sort{
\field{presort}
}
\sort[final]{
\field{sortkey}
}
\sort{
\field{usera}
}
\sort{
\field{sortname}
\field{author}
\field{editor}
\field{translator}
\field{sorttitle}
\field{title}
}
\sort{
\field{sortyear}
\field{year}
}
}
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=author]
\step[fieldset=usera, origfieldval]
\step[fieldsource=usera, match=\regexp{.+?\sand\s}, replace=\regexp{and}]
\step[fieldsource=usera, match=\regexp{((?:and)*).+}, replace=\regexp{\$1}]
}
}
}

\begin{document}

\nocite{*}
\printbibliography
\end{document}

• Gorgeous! Am I asking too much if I suggest to you to answer also this? Nov 3, 2016 at 7:31
• I would have used e.g. usera as target for the regex, imho expanding the datamodel isn't really needed for such an one time requirement. And now I won't be able to get my bribe and never know who is responsable for such rules ;-(. Nov 3, 2016 at 8:34
• You are right about using usera - I was looking into making numauthors into a real integer field which would have needed datamodel extensions but it's not worth the messy effort with regexps.
– PLK
Nov 3, 2016 at 15:08
• Thank you for your help - this is great! Sorry @UlrikeFischer, you have to live with the knowledge, that out there, somewhere in your country, people have to comply to this rule ;).
– DrA
Nov 3, 2016 at 15:42
• @DrA I doubt that you really have to comply. But you don't care enough to take a risk and do something about it -- one of the reason why silly rules stay sometimes for ever. Nov 3, 2016 at 17:08

I think the easiest way to reach that crazy way of sorting is to add an appropriate sortname in the bib items whose order you want to change:

\begin{filecontents}{crazybib.bib}
@article{AuthorA2010,
title={Titlea},
author={Author, Alan},
journal={Journala},
volume={10},
pages={1--3},
year={2010},
publisher={Publishera}
}%
@article{AuthorAC2005,
title={Titleac},
author={Author, Alan and Cuthor, Carla},
journal={Journalac},
volume={10},
pages={1--3},
year={2005},
publisher={Publisherac}
}%
author={Author, Alan and Duthor, David},
volume={10},
pages={1--3},
year={1990},
}%
author={Author, Alan and Duthor, David},
volume={10},
pages={1--3},
year={2000},
}%
@article{AuthorABD2000,
title={Titleabd},
author={Author, Alan and Bill Buthor and Cuthor, Carla},
sortname={Author, Alan and Zzzz},% or everything makes the sort correct
journal={Journalabd},
volume={10},
pages={1--3},
year={2000},
publisher={Publisherabd}
}%
\end{filecontents}

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}

\usepackage[english]{babel}

\usepackage[style=authoryear, natbib=true, backend=biber,firstinits=true, dashed=false]{biblatex}
\usepackage{csquotes}