Monday, July 24, 2017

Biblatex, citations and bibliography sorting

"I want to sort in-text citations by year, but bibliography by name."  So begins one of the questions at a Stackexchange.  That's just what I want too.

I want to put multiple references in a \cite{} command without caring about their sequence, and have them automatically print in year-order.  Then, I want my bibliography to be ordinary, i.e., printed in author-date order.

The discussion at the above site is tricky, but the answer by moewe works. 

NB: update in 2024. After biblatex ver. 3.18, the way to do this changed.  The old, pre 3.18, method is appended below.  But since 2022, 

Current, post-2022 method

\documentclass{article}
\usepackage[backend=biber,
  style=authoryear-comp,
  % sortcites=true, % not needed here because it is implied by style=authoryear-comp,
]{biblatex}
\AtBeginRefsection{\GenRefcontextData{sorting=ynt}}
\AtEveryCite{\localrefcontext[sorting=ynt]}
\addbibresource{mybibliography.bib} 

\begin{document}
  Lorem \autocite{key2000, key1900}

  ipsum \autocite{key1900, key2000}

  \printbibliography
\end{document}


There is another post by moewe that rewrites the \cites command so that also obeys sortcites (which it doesn't by default).


Old, pre-2022 method, for historical interest

In a nutshell here's what you actually do:

\begin{document}
\usepackage[sorting=ynt,sortcites=true]{biblatex}
\addbibresource{mybibliography.bib}
\AtBeginDocument{\assignrefcontextentries[]{*}}
\begin{document}
Hello world!\footcites{ref1,ref3,ref0,ref4}
\newrefcontext[sorting=nyt]
\printbibliography

\end{document}
This will print your footnoted citations in ascending order of year, and your bibliography in ascending order of author.