5

I need to order my bibliography on alphabetical order. However, the works headed by the same first author must be ordered as follows:
1º Works with one authors, in chronological order.
2º Works with two authors, in chronological order.
3º Works with three authors, in chronological order.

I have my preamble as follows:

\usepackage[autostyle=true]{csquotes}  
\usepackage[backend=biber,style=authoryear,style=bwl-FU,natbib=true,hyperref=true,maxbibnames=100,maxcitenames=2,sorting=nyt,uniquelist=false,uniquename=false]{biblatex}%para bibliografía  
\addbibresource{BibM.bib}
\DeclareSourcemap{  
  \maps[datatype=bibtex]{  
    \map{  
      \step[fieldsource=author, match=\regexp{(.*?)\s+and\s+}]  
      \step[fieldset=sortname, fieldvalue={$1}]  
       }  
  }  
}  

These are a few entries of my .bib:

@article{Takahashi2007, 
author = {Takahashi, K. and Tanabe, K. and Ohnuki, M. and Narita, M. and Ichisaka, T. and Tomoda, K. and Yamanaka, S.},  
journal = {Cell}, 
pages = {861--872},  
title = {{Induction of Pluripotent Stem Cells from Adult Human Fibroblasts by Defined Factors}},  
volume = {131},  
year = {2007}  
}  
@article{Takahashi2016a,  
author = {Takahashi, K. and Yamanaka, S.}, 
journal = {Nature Reviews Molecular Cell Biology},  
pages = {183--193}, 
title = {{A decade of transcription factor-mediated reprogramming to pluripotency}},  
volume = {17},  
year = {2016}  
}  
@article{Takahashi2006,  
author = {Takahashi, K. and Yamanaka, S.},  
journal = {Cell},  
pages = {663--676}, 
title = {{Induction of Pluripotent Stem Cells from Mouse Embryonic and Adult Fibroblast Cultures by Defined Factors}},    
volume = {126},  
year = {2006}  
}  

With this LaTex does order the works with the same first author by year. However, I don't know how to make it prioritize the number of authors: Example of wrongly sorted works

Sorry if my question is messy, I'm new to both latex and the site.
Thank you very much!

| improve this question | | | | |
  • 2
    Your question is fairly clear as it stands now (I think, I might have misunderstood parts of it), but you can make it easier for people to give a good answer if you provide a full MWE/MWEB with a few example .bib entries instead of just a code snippet of your preamble. An MWE makes sure that we are all talking about the same thing and it is a way to say that you appreciate the time that people spend working on your question by not letting them reproduce the work you have done already. – moewe Jun 4 '18 at 18:02
  • Thank you, I have added the .bib examples from the picture. I hope the question is better now. – Aiora Jun 4 '18 at 18:19
  • @Aiora, you can use the {} to format blocks of code whenever you edit/ask. And, as moewe said, things might be easier if you provided a MWE (follow the links in his comment). – gusbrs Jun 4 '18 at 18:24
  • Thank you very much, I will use the {} for the code from now on. I also tried erasing the stuff that wasn't necessary to solve the reference sorting, I hope its okay now. I'm sorry for the trouble. – Aiora Jun 4 '18 at 19:21
  • Related tex.stackexchange.com/q/337147/35864 – moewe Jun 4 '18 at 19:31
2

Combining PLK's answer to How to sort reference list depending on the number of authors with Biblatex? and my answer to Biblatex sorting not working properly we can obtain

\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}
}
@article{AuthorAD1990,
  title={Titlead},
  author={Author, Alan and Duthor, David},
  journal={Journalad},
  volume={10},
  pages={1--3},
  year={1990},
  publisher={Publisherad}
}
@article{AuthorAD2000,
  title={Titlead two},
  author={Author, Alan and Duthor, David},
  journal={Journalad two},
  volume={10},
  pages={1--3},
  year={2000},
  publisher={Publisherad two}
}
@article{AuthorABD2000,
  title={Titleabd},
  author={Author, Alan and Bill Buthor and Cuthor, Carla},
  journal={Journalabd},
  volume={10},
  pages={1--3},
  year={2000},
  publisher={Publisherabd}
}
@article{Takahashi2007,
author = {Takahashi, K. and Tanabe, K. and Ohnuki, M. and Narita, M. and Ichisaka, T. and Tomoda, K. and Yamanaka, S.},
journal = {Cell},
pages = {861--872},
title = {{Induction of Pluripotent Stem Cells from Adult Human Fibroblasts by Defined Factors}},
volume = {131},
year = {2007}
}
@article{Takahashi2016a,
author = {Takahashi, K. and Yamanaka, S.},
journal = {Nature Reviews Molecular Cell Biology},
pages = {183--193},
title = {{A decade of transcription factor-mediated reprogramming to pluripotency}},
volume = {17},
year = {2016}
}
@article{Takahashi2006,
author = {Takahashi, K. and Yamanaka, S.},
journal = {Cell},
pages = {663--676},
title = {{Induction of Pluripotent Stem Cells from Mouse Embryonic and Adult Fibroblast Cultures by Defined Factors}},
volume = {126},
year = {2006}
}
\end{filecontents}
\usepackage[style=authoryear,firstinits=true, dashed=false,sorting=custsort]{biblatex}
\addbibresource{\jobname.bib}

\DeclareSortingScheme{custsort}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{usera}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
}
\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=author, match=\regexp{(.*?)\s+and\s+}]
      \step[fieldset=sortname, fieldvalue={$1}]
    }
    \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}

enter image description here

Note how the year breaks the sorting tie between the works authored by Author and on co-author. Furthermore the works Takahashi wrote with Yamanaka are listed before the works written together with Tanabe and others even though alphabetically it would be otherwise if all names were considered for sorting.

So how does this work?

The first \map makes sure that only the first name in a list goes to sortname. The second map counts the number of co-authors by extracting only the ands from the author field to usera (it will contain exactly one and for each co-author). The sorting scheme then sorts by name (sortname contains only the lead author) and usera (number of authors) and finally year.

| improve this answer | | | | |
  • A clever trick! – gusbrs Jun 4 '18 at 19:51
  • @gusbrs Indeed. All credits go to PLK. I knew I had seen a question like this before I just needed to find it. Needless to say I find this kid of sorting quite weird. – moewe Jun 4 '18 at 19:57
  • Me too. Still, there is the fun of seeing how it can be done. :) – gusbrs Jun 4 '18 at 20:04
  • It worked wonderfully. Thanks a lot for the solution and the wonderful explanation! – Aiora Jun 4 '18 at 20:19
  • @Aiora Great! If the answer helped you, you may want to consider up-voting and accepting it, see tex.stackexchange.com/help/someone-answers. – moewe Jun 4 '18 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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