# Sorting issue with biblatex

For several years, thanks to this forum, I succeeded for my thesis to achieve a bibliographic style adapted to my needs. However, I just realized now that it is well developed, a sorting issue.

I would like to be sorted by my label and not by name. I would like to have first the author alone, then two authors and finally "authors et al." in ascending order

I found some answers here: How to establish a complex sorting scheme of references in biblatex? However, this seems to create more problems than it solves.

Here is my problem in pictures which will be easier to understand Here is what I have: This is what i would like:

Thanks, PS: sorry for my big MWE:

\documentclass{article}
\usepackage{csquotes}
\usepackage{polyglossia}
\setdefaultlanguage{french}

\usepackage[%
backend=biber,
style=authoryear,
autolang=langname,
uniquename=false, %%enleve le système pour désambiguiser les auteurs
uniquelist=false, %enleve le système pour désambiguiser les auteurs
giveninits,
mergedate=false,
sorting=nyt,
maxcitenames=2,
maxbibnames=999,
mincrossrefs=1, %permet de citer l'entrée mère dès la première mention
]{biblatex}

\begin{filecontents}{\jobname.bib}

@InProceedings{agusta-boularot2017,
author    = {Agusta-Boularot, Sandrine},
title     = {Title},
booktitle = {booktitle},
year      = {2017},
crossref  = {agusta-boularot.etal2017},
}

@InProceedings{agusta-boularot2016,
author    = {Sandrine Agusta-Boularot},
title     = {Title},
year      = {2016},
booktitle = {booktitle},
}

@Book{agusta-boularot.lafon2004,
title     = {title},
year      = {2004},
editor    = {Sandrine Agusta-Boularot and Xavier Lafon},
}

@Book{agusta-boularot.martin2006,
title     = {title},
year      = {2006},
editor    = {Sandrine Agusta-Boularot and Marin Martin},
}

@InProceedings{augustat-boularot.etal2019,
author    = {Sandrine Agusta-Boularot and Chausserie-Laprée, Jean and N\'uria Nin},
title     = {Title},
booktitle = {booktitle},
year      = {2019},
timestamp = {2019-09-11},
}

@Article{agusta-boularot.etal2004,
author       = {Agusta-Boularot, Sandrine and Christol Martin and Pierre Jack},
title        = {Title},
journal      = {Journal},
year         = {2004},
volume       = {17},
}

@Article{agusta-boularot.etal2010,
author       = {Sandrine Agusta-Boularot and Raphaël Golosetti and Delphine Isoardi},
title        = {Title},
journal      = {Journal},
year         = {2010},
pages        = {109-126},
volume       = {43},
}

@Book{agusta-boularot.etal2017,
editor    = {Sandrine Agusta-Boularot and Sandrine Huber and William Van Andringa},
title     = {Title},
year      = {2017},
}

@InProceedings{paillet.treziny2004,
author    = {Paillet, Jean-Louis and Henri Tr\'eziny},
title     = {Title},
booktitle = {booktitle},
year      = {2004},
editor    = {Agusta-Boularot, Sandrine},
crossref  = {agusta-boularot.etal2004},
timestamp = {2019-12-09},
}

\end{filecontents}

%%%style
\renewcommand*{\revsdnamepunct}{}
\renewcommand*{\finalnamedelim}{\multinamedelim}
\renewcommand*{\mkbibnamefamily}[1]{\textsc{#1}}
\DeclareNameAlias{byeditor}{sortname}
\DeclareNameAlias{sortname}{family-given}

\renewcommand*{\labelnamepunct}{\space\textendash\space}                  %tiret après le label
\renewbibmacro*{date+extrayear}{}%                                            rajoute date

\DeclareFieldFormat
[article,inbook,incollection,inproceedings,patent,unpublished]
{title}{#1}
\renewbibmacro{in:}{%                                                                 enlève guillemets articles
\ifentrytype{article}
{}
{\printtext{\bibstring{in}\intitlepunct}}}

\renewbibmacro*{issue+date}{%
\printfield{issue}%
\printdate%
\newunit}

\DeclareFieldFormat{postnote}{#1} %enlève le p. automatique pour le postnote dans les citations

\renewbibmacro*{publisher+location+date}{%
\printlist{location}%
\printlist{publisher}%
\usebibmacro{date}%
\newunit}

%permet de mettre des virgules à la place des deux points après l'adresse
\newbibmacro*{institution+location+date}{%
\printlist{location}%
\printlist{institution}%
}

%Make all thesis/dissertation titles italic
\DeclareFieldFormat[thesis]{title}{\mkbibitalic{#1}}% %met les titres des theses en italique ; permet également d'enlever les guillements

%Enlever le tiret lorsqu'il y a une récurrence des auteurs
\makeatletter
\AtEveryBibitem{%
\global\undef\bbx@lasthash%
\clearfield{extraalpha}}
\makeatother

% "Et al." en ITALIQUE
\renewbibmacro*{name:andothers}{% Based on name:andothers from biblatex.def
\ifboolexpr{
test {\ifnumequal{\value{listcount}}{\value{liststop}}}
and
test \ifmorenames
}
{\ifnumgreater{\value{liststop}}{1}
{\finalandcomma}
{}%
\andothersdelim\bibstring[\emph]{andothers}}
{}}

%%% Histoire des noms    et al...
\makeatletter
\renewbibmacro*{begentry}{%
\renewcommand*{\mkbibnamefamily}[1]{##1}%
\defcounter{maxnames}{\blx@maxcitenames}%
\defcounter{maxnames}{\blx@maxbibnames}
\renewcommand*{\mkbibnamefamily}[1]{\textsc{\textnohyphenation{##1}}}}
\makeatother

%minuscule citation
\AtBeginDocument{\renewcommand*{\mkbibnamefamily}[1]{#1}}

%Enlève parenthèse colloque
\renewbibmacro*{event+venue+date}{
\iffieldundef{eventtitle}
{}
{%
\bibstring{presentedat}%
\printfield{eventtitle}%
}%
\ifboolexpr{
test {\iffieldundef{venue}}
and
test {\iffieldundef{eventyear}}
}
{}
\printtext{%
\printfield{venue}%
\printeventdate}}%
\newunit
}

\DefineBibliographyStrings{french}{%
byeditor = \iffieldequalstr{keywords}{source}%
{Établit\space par}%
in = {\textit{in}},%                                    %et en italique
idem = {\emph{idem}},%
byeditor = {dir\adddot},% Remplace sous la direction de pour les improceedings etc.
mathesis = {Mém. de master\addcomma}, %permet de modifier en français le titre et de rajouter un point un espace et une virigule
phdthesis = {Thèse de doct\adddot\space\addcomma} %permet de modifier en français le titre et de rajouter un point un espace et une virigule
}

%%modifie les pages des articles ... par pp. au lieu de p.

%enlève la virugule avant dir.
\makeatletter
\renewbibmacro*{bbx:editor}[1]{%
\ifboolexpr{
test \ifuseeditor
and
not test {\ifnameundef{editor}}
}
{\usebibmacro{bbx:dashcheck}
{\bibnamedash}
{\printnames{editor}%
\usebibmacro{bbx:savehash}}%
%     \usebibmacro{#1}% DELETED
\clearname{editor}}
{\global\undef\bbx@lasthash}}
\makeatother

% put (dir.) at the end (byeditor)  pour tout ce qui est in : auteur dir.
\renewbibmacro*{byeditor+others}{%
\ifnameundef{editor}
{}
\printnames[byeditor]{editor}%
\clearname{editor}%            %%%%%%%%%
\newunit}%
\usebibmacro{byeditorx}%
\usebibmacro{bytranslator+others}}

%met entre parenthèse la collection et le numéro dans la même parenthèse
\renewbibmacro*{series+number}{%
\iffieldundef{series}
{}
{\printtext[parens]{%
\printtext{}%
\printfield{series}%
\setunit*{\space}%
\printfield{number}%
\printtext{}}%
}} %%% il y a un point en enleveant \nopunct.

%Rajoute une virgule après le titre du journal et avant le numéro du volume
\renewbibmacro*{journal+issuetitle}{%
\usebibmacro{journal}%
\iffieldundef{series}
{}
{\newunit
\printfield{series}%
\usebibmacro{volume+number+eid}%
\usebibmacro{issue+date}%
\usebibmacro{issue}%
\newunit}

%Permet d'enlever le tiret après in si pas d'auteur.
\renewbibmacro{in:}{%
\ifentrytype{article}
{}
{\printtext{\bibstring{in}}%
\printunit{\intitlepunct}}}

%permet de mettre les initiales entre parenthèses et surtout les particules nobilaires

\renewbibmacro*{name:family-given}[4]{%
\ifuseprefix
{\usebibmacro{name:delim}{#3#1}%
\usebibmacro{name:hook}{#3#1}%
\ifdefvoid{#3}{}{%
\ifcapital
{\mkbibnameprefix{\MakeCapital{#3}}\isdot}
{\mkbibnameprefix{#3}\isdot}%
\ifprefchar{}{\bibnamedelimc}}%
\mkbibnamefamily{#1}\isdot
\ifdefvoid{#4}{}{\bibnamedelimd\mkbibnamesuffix{#4}\isdot}%
{\usebibmacro{name:delim}{#1}%
\usebibmacro{name:hook}{#1}%
\mkbibnamefamily{#1}\isdot
\ifdefvoid{#4}{}{\bibnamedelimd\mkbibnamesuffix{#4}\isdot}%
%   \ifdefvoid{#2#3}{}{\revsdnamepunct}%
\ifboolexpe{%
test {\ifdefvoid{#2}}
and
test {\ifdefvoid{#3}}}
{}
{\bibcloseparen}}}% this line is new

%permet de mettre en minustile les styles de citation
\DefineBibliographyExtras{french}{\restorecommand\mkbibnamefamily}

%rajoute origdate
\renewbibmacro*{cite:labelyear+extrayear}{%
\iffieldundef{labelyear}
{}
{\printtext[bibhyperref]{%
\printfield{labelyear}%
\printfield{extrayear}}}}

\renewbibmacro*{date+extrayear}{%
\iffieldundef{year}
{}
{\printtext[parens]{%
\printdateextra}}}

%%%%Permet de trier la biblio en suivant l'ordre du label et non pas des noms
%\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{emi}{
%   \sort{
%       \field{sortname}
%       \field{author}
%   }
%   \sort{\field{year}}
%   \sort{\citeorder}
%}

\begin{document}

\cite{agusta-boularot2017,agusta-boularot2016,agusta-boularot.lafon2004,augustat-boularot.etal2019,agusta-boularot.etal2004,agusta-boularot.etal2010,agusta-boularot.etal2017,paillet.treziny2004,agusta-boularot.martin2006}

\printbibliography[sorting=emi]

\end{document}

• This is definitely not supported 'officially' in the sense that while Biber has the data available to sort your entries like this there is no interface to specify that. I would have suggested something pretty much along the line of Audrey's answer to the linked question (I think we have a few other related question, but they are had to find ... I will have a look later), but those solutions can be a bit flimsy and usually have edge cases they can't deal with properly. – moewe May 15 '20 at 12:20
• The best combination of search keywords I could think of is tex.stackexchange.com/search?q=declaresourcemap+sortname, but there are 50 something hits. Not sure if there is something useful in that list. – moewe May 15 '20 at 12:21
• Thank you, I will try to look again on the forum if I find something close to it. It is surprising that this sorting is not more easily accessible because it is often used in France. Indeed, if you have time to take a look it would be wonderful because these lines of code are completly arcane for me. – Axelito May 16 '20 at 8:09

If I understand correctly, it should be enough to set maxsortnames=2, (i.e. to the same value as maxcitenames). Note that maxsortnames must be set after maxbibnames (because maxbibnames sets maxsortnames for backwards compatibility, see https://github.com/plk/biblatex/issues/755). maxsortnames needs at least biblatex v3.12 (2018-10-30).

maxsortnames=2, is enough because it forces biblatex to sort by exactly the same names that appear in the citation label. "<Name> et al." is always sorted after <Name> (unless nosortothers is set to true, see https://github.com/plk/biblatex/issues/861). And <Name> <Name 2> also always sorts after <Name> but before <Name> et al..

So you want to load biblatex with the following name options

  maxbibnames=999,
maxcitenames=2,
maxsortnames=2,
uniquename=false,
uniquelist=false,
giveninits,


I modernised your MWE slightly and removed redundant code. I also based it onto ext-authoryear from my biblatex-ext bunde (instead of authoryear), since that makes a few things much easier (for example the bold repetition of the citation label can be produced with the option introcite=true,). (Needless to say I probably missed a few things and this does not completely reproduce the exact style you have at the moment. In case you want to pursue this further, just ask a new question about the things I missed. Ideally one issue per question.)

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{french}
\usepackage{csquotes}

\usepackage[%
backend=biber,
style=ext-authoryear,
maxbibnames=999,
maxcitenames=2,
maxsortnames=2,
uniquename=false,
uniquelist=false,
giveninits,
mincrossrefs=1,
mergedate=false,
dashed=false,
introcite=plain,
autolang=langname,
]{biblatex}

\DeclareFieldFormat{bbx@introcite}{\mkbibbold{#1}}

\DefineBibliographyExtras{french}{\restorecommand\mkbibnamefamily}
\renewcommand*{\mkbibnamefamily}[1]{\textsc{#1}}
\AtEveryCitekey{\renewcommand*{\mkbibnamefamily}[1]{#1}}

\DeclareDelimAlias{finalnamedelim}{multinamedelim}

\DeclareNameAlias{byeditor}{sortname}
\DeclareNameAlias{sortname}{family-given}

\renewbibmacro*{name:family-given}[4]{%
\ifuseprefix
{\usebibmacro{name:delim}{#3#1}%
\usebibmacro{name:hook}{#3#1}%
\ifdefvoid{#3}{}{%
\ifcapital
{\mkbibnameprefix{\MakeCapital{#3}}\isdot}
{\mkbibnameprefix{#3}\isdot}%
\ifprefchar{}{\bibnamedelimc}}%
\mkbibnamefamily{#1}\isdot
\ifboolexpe{%
test {\ifdefvoid{#2}}
and
test {\ifdefvoid{#4}}}
{}
{\bibnamedelimd\bibopenparen}%
\ifdefvoid{#2}{}{\mkbibnamegiven{#2}\isdot}%
\ifdefvoid{#4}{}{\ifdefvoid{#2}{}{\bibnamedelimd}\mkbibnamesuffix{#4}\isdot}%
\ifboolexpe{%
test {\ifdefvoid{#2}}
and
test {\ifdefvoid{#4}}}
{}
{\bibcloseparen}}
{\usebibmacro{name:delim}{#1}%
\usebibmacro{name:hook}{#1}%
\mkbibnamefamily{#1}\isdot
\ifdefvoid{#4}{}{\bibnamedelimd\mkbibnamesuffix{#4}\isdot}%
\ifboolexpe{%
test {\ifdefvoid{#2}}
and
test {\ifdefvoid{#3}}}
{}
{\revsdnamepunct\bibopenparen}%
\ifdefvoid{#2}{}{\mkbibnamegiven{#2}\isdot}%
\ifdefvoid{#3}{}{\ifdefvoid{#2}{}{\bibnamedelimd}\mkbibnameprefix{#3}\isdot}%
\ifboolexpe{%
test {\ifdefvoid{#2}}
and
test {\ifdefvoid{#3}}}
{}
{\bibcloseparen}}}

\renewbibmacro*{name:andothers}{% Based on name:andothers from biblatex.def
\ifboolexpr{
test {\ifnumequal{\value{listcount}}{\value{liststop}}}
and
test \ifmorenames
}
{\ifnumgreater{\value{liststop}}{1}
{\finalandcomma}
{}%
\andothersdelim\bibstring[\emph]{andothers}}
{}}

\DeclareFieldFormat{origdate}{\mkbibbrackets{#1}}
\iffieldundef{labelyear}
{}
{\printtext[bibhyperref]{%
\printorigdate
\printlabeldateextra}}}

\renewbibmacro*{date+extrayear}{%
\iffieldundef{year}
{}
{\printtext[parens]{%
\printorigdate
\printdateextra}}}

\DeclareDelimFormat[bib]{nametitledelim}{\space\textendash\space}

\DeclareFieldFormat
[article,inbook,incollection,inproceedings,patent,unpublished]
{title}{#1}
\DeclareFieldFormat[thesis]{title}{\mkbibitalic{#1}}

\renewbibmacro{in:}{%
\ifentrytype{article}
{}
{\printtext{\bibstring{in}\intitlepunct}}}

\renewbibmacro*{byeditor+others}{%
\ifnameundef{editor}
{}
\printnames[byeditor]{editor}%
\clearname{editor}%
\newunit}%
\usebibmacro{byeditorx}%
\usebibmacro{bytranslator+others}}

\renewbibmacro*{issue+date}{%
\printfield{issue}%
\printdate%
\newunit}

\renewbibmacro*{series+number}{%
\iffieldundef{series}
{}
{\printtext[parens]{%
\printfield{series}%
\setunit*{\space}%
\printfield{number}}}}

\renewbibmacro*{publisher+location+date}{%
\printlist{location}%
\printlist{publisher}%
\usebibmacro{date}%
\newunit}

\newbibmacro*{institution+location+date}{%
\printlist{location}%
\printlist{institution}%

\renewbibmacro*{event+venue+date}{%
\iffieldundef{eventtitle}
{}
{\bibstring{presentedat}%
\printfield{eventtitle}}%
\ifboolexpr{
test {\iffieldundef{venue}}
and
test {\iffieldundef{eventyear}}
}
{}
\printfield{venue}%
\printeventdate}%
\newunit
}

%\DeclareFieldFormat[article,inbook,inproceedings,incollection]
%  {pages}{\mkpageprefix[bookpagination]{#1}}

\DeclareFieldFormat{postnote}{\mknormrange{#1}}

\DefineBibliographyStrings{french}{%
byeditor  = {\iffieldequalstr{keywords}{source}
{Établit\space par}%
in        = {\textit{in}},
opcit     = {\iffieldequalstr{entrytype}{article}
idem      = {\mkbibemph{idem}},%
}

\begin{filecontents}{\jobname.bib}
@InProceedings{agusta-boularot2017,
author    = {Agusta-Boularot, Sandrine},
title     = {Title},
booktitle = {booktitle},
year      = {2017},
crossref  = {agusta-boularot.etal2017},
}
@InProceedings{agusta-boularot2016,
author    = {Sandrine Agusta-Boularot},
title     = {Title},
year      = {2016},
booktitle = {booktitle},
}
@Book{agusta-boularot.lafon2004,
title     = {title},
year      = {2004},
editor    = {Sandrine Agusta-Boularot and Xavier Lafon},
}
@Book{agusta-boularot.martin2006,
title     = {title},
year      = {2006},
editor    = {Sandrine Agusta-Boularot and Marin Martin},
}
@InProceedings{augustat-boularot.etal2019,
author    = {Sandrine Agusta-Boularot and Chausserie-Laprée, Jean and Núria Nin},
title     = {Title},
booktitle = {booktitle},
year      = {2019},
timestamp = {2019-09-11},
}
@Article{agusta-boularot.etal2004,
author       = {Agusta-Boularot, Sandrine and Christol Martin and Pierre Jack},
title        = {Title},
journal      = {Journal},
year         = {2004},
volume       = {17},
}
@Article{agusta-boularot.etal2010,
author       = {Sandrine Agusta-Boularot and Raphaël Golosetti and Delphine Isoardi},
title        = {Title},
journal      = {Journal},
year         = {2010},
pages        = {109-126},
volume       = {43},
}
@Book{agusta-boularot.etal2017,
editor    = {Sandrine Agusta-Boularot and Sandrine Huber and William Van Andringa},
title     = {Title},
year      = {2017},
}
@InProceedings{paillet.treziny2004,
author    = {Paillet, Jean-Louis and Henri Tréziny},
title     = {Title},
booktitle = {booktitle},
year      = {2004},
editor    = {Agusta-Boularot, Sandrine},
crossref  = {agusta-boularot.etal2004},
timestamp = {2019-12-09},
}
\end{filecontents}

\begin{document}
\autocite{agusta-boularot2017, agusta-boularot2016, agusta-boularot.lafon2004,
augustat-boularot.etal2019, agusta-boularot.etal2004,
agusta-boularot.etal2010, agusta-boularot.etal2017,
paillet.treziny2004, agusta-boularot.martin2006}

\printbibliography
\end{document}


• Thank you very much, I tried but it doesn't work because my version of texlive was not up to date. It was from 2017 ... I am downloading it but my connection is slow ... very slow – Axelito May 17 '20 at 14:56
• Thank you very much for sorting and modernizing the code. Everything works well. The authoryear-ext supplement is very practical. I managed to add the changes I wanted. In order to have commas everywhere I added: \ renewcommand * {\ newunitpunct} {\ addcomma \ space}. But is it possible to put an exception for punctuation after the titles of articles and books? – Axelito May 18 '20 at 13:09
• New problem ... I think I'll have to make a new topic. When I use "innamebeforetitle= true" the parentheses and the inversion First name / Last name is canceled – Axelito May 18 '20 at 14:53
• @Axelito The punctuation between author and title can be changed with \DeclareDelimFormat[bib]{nametitledelim}{\space\textendash\space} (as shown in the example). Please ask a new question about the other issue. Include the code you are using now and an example of how it does not give the expected result. – moewe May 18 '20 at 15:36