# How to establish a complex sorting scheme of references in biblatex?

The journal in which I intend to publish has some weird sorting requirements for the reference list. The basic sorting is alphabetical but then (quoting from here):

1. "Papers with two authors should follow those of the first-named author, arranged in alphabetical order according to the name of the second author."
2. "Articles with more than two authors should follow those of the first named author in chronological order"
3. "with multiple references from the same first author in a given year, please list the references in cited order."

Number 1 is of course automatically achieved using sorting = nyt but how do I include requirements 2 and 3? I'm guessing the solution should involve \DeclareSortingScheme{} but I haven't got a clue how to code this.

-
The publishers are clearly sadists. My advice would be to just ignore that nonsense ... if the publishers care so much, they can have professional typesetters implement their weird reference fetishes. That should not be your responsibility as an author. Otherwise, they have made a .bst file available here: biometrics.tibs.org/biom.bst.txt. Not sure on the mechanics of how that could be included in biblatex specifically. –  badroit Nov 22 '12 at 1:24
I should add, the above file is linked for another journal from the same publishers: biometrics.tibs.org/latexdocumentclass.htm. –  badroit Nov 22 '12 at 1:27
Does the journal provide a LaTeX template? With or without biblatex? Or do they want a pdf file or a word document submitted? –  Kurt Nov 22 '12 at 2:11
Journal publishers are known to be sadistic, which would've been accepted if they wouldn't be making such profits on the backs of scientists... The journal doesn't provide any LaTeX template (did I mention already they profit from our work without doing much ...). I haven't looked into the .bst file since: 1. I'm using biblatex and not bibtex and 2. I'm almost done with my bbx style anyway. –  Roey Angel Nov 22 '12 at 9:44

It isn't really clear how these rules should be combined. Based on reference lists recently published in this journal it appears that any two-author paper should precede a three-or-more-author work having the same first author, regardless of chronology. A similar precedent holds for one-author and two-author works. You can achieve all this by copying the first author and some "large" value into the sortname field for every entry with more than two authors.

For one- or two-author entries sortname can be left missing by adding the whole author list to the same sorting element, as done in the new sorting scheme emi below. Further requirements related to citation sorting and name list truncation can easily be achieved with some global option settings. The document also demonstrates a few of these.

\documentclass{article}
\usepackage{csquotes}
\usepackage[american]{babel}
\usepackage[backend=biber,style=authoryear,sortcites,sorting=noneyear,
maxcitenames=1,minbibnames=6,maxbibnames=7]{biblatex}

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite]{
\step[fieldsource=author,match=\regexp{\s+and\s.+\s+and\s},final]
\step[fieldset=sortname,origfieldval]
\step[fieldsource=sortname,match=\regexp{\s+and\s.+},replace={\ and\ Zzz}]
}
}
}

\DeclareSortingScheme{noneyear}{
\sort{\citeorder}
\sort{\field{year}}
}

\DeclareSortingScheme{emi}{
\sort{
\field{sortname}
\field{author}
}
\sort{\field{year}}
\sort{\citeorder}
}

\begin{filecontents}{\jobname.bib}
@article{ref1,
author = {First, Joe and Second, Jane and Third, Bob},
title = {Article title},
journaltitle = {Journal},
date = {2001-01}}
@article{ref2,
author = {First, Joe and Second, Jane and Third, Bob},
title = {Article title},
journaltitle = {Journal},
date = {2000-01}}
@book{ref3,
author = {First, Joe and Third, Bob},
title = {Book title},
year = {2002}}
@book{ref4,
author = {Doe, Joe and Smith, Sam},
title = {Book title},
date = {2001}}
@book{ref5,
author = {Doe, Joe and Brown, Bob},
title = {Book title},
date = {2002}}
@book{ref6,
author = {First, Joe},
title = {Book title},
date = {2003}}
\end{filecontents}

\begin{document}
Filler \parencite{ref1,ref2,ref3,ref4,ref5,ref6}.
Filler \parencite{knuth:ct:c,knuth:ct:b,knuth:ct:a}.
\printbibliography[sorting=emi]
\end{document}


-
Thanks a lot Audrey for the thorough reply! Your code works great. The only reason I was slow to reply is that I had trouble getting your method to work with my real document. Then I realized that the reason is that I had another \DeclareSourcemap{ command called from another file using \input a few lines later and it ran over yours. Is there a way to have two \DeclareSourcemap{ commands in one preamble? I tried naming them with \DeclareSourcemap{name}{ but that gave an error. –  Roey Angel Nov 22 '12 at 17:58
@RoeyAngel There actually is no need for multiple source map declarations. In \maps you can use multiple \map statements. They are executed in order of appearance. I can clarify with an edit, but I probably need an idea of what mapping other rules you need. –  Audrey Nov 22 '12 at 19:57
Thanks, I know how to use multiple \map statements in one \DeclareSourcemap call the only thing is that my other \map call is a file containing many reg exp patterns for turning journal names into abbreviations. The only trouble is that now the code looks a bit ugly. I mind about that because I want others to use the style I'm writing. On the other hand if I can 'shove' everything into the .bbx file that should be ok. –  Roey Angel Nov 22 '12 at 22:42
@RoeyAngel Yeah, I thought a little more and figured you might want an "author-level" source map separate from the user one in the preamble. I asked Philip about it at github. You can follow the issue here. –  Audrey Nov 23 '12 at 2:35
Brilliant! I think adding an option of a localized \DeclareStyleSourcemap would enhance a lot the flexibility of biblatex and will allow me and others to provide more 'intact' biblatex styles, which will require little to no further tweaking on the part of the users. –  Roey Angel Nov 23 '12 at 11:17