Update
With biblatex
v3.18 and above you can use \localrefcontext
and \GenRefcontextData
to switch to a different reference context (e.g. sorting).
Use
\AtBeginRefsection{\GenRefcontextData{sorting=ynt}}
to make sure that each refcontext
our document uses also generates an analogous refcontext
with ynt
sorting.
Then
\AtEveryCite{\localrefcontext[sorting=ynt]}
switches our citations to the ynt
sorting refcontext
. \localrefcontext
only acts locally and need not be "closed" or reset because it happens inside a group.
\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]}
\begin{filecontents}{\jobname.bib}
@book{key2000,
author = {Author, A.},
year = {2000},
title = {Alphabetical fist \& Year last},
publisher = {Publisher},
}
@book{key1900,
author = {Boathor, B.},
year = {1900},
title = {Alphabetical last \& Year first},
publisher = {Publisher},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
Lorem \autocite{key2000, key1900}
ipsum \autocite{key1900, key2000}
\printbibliography
\end{document}
See also Sort citations by year (ynt) and references by name (nyt) in custom biblatex style.
Solution for older versions of biblatex
Give the desired citation sort order at loading time. Then give the desired order for the bibliography in the new refcontext (\begin{refcontext}[sorting=<sorting>]...\end{refcontext}
) for \printbibliography
.
\documentclass{article}
\usepackage[backend=biber,
style=authoryear-comp, sorting=ynt,
% sortcites=true, % not needed here because it is implied by style=authoryear-comp,
]{biblatex}
\begin{filecontents}{\jobname.bib}
@book{key2000,
author = {Author, A.},
year = {2000},
title = {Alphabetical fist \& Year last},
publisher = {Publisher},
}
@book{key1900,
author = {Boathor, B.},
year = {1900},
title = {Alphabetical last \& Year first},
publisher = {Publisher},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
Lorem \autocite{key2000, key1900}
ipsum \autocite{key1900, key2000}
\begin{refcontext}[sorting=nyt]
\printbibliography
\end{refcontext}
\end{document}
I used
\begin{refcontext}[sorting=nyt]
\printbibliography
\end{refcontext}
instead of the slightly shorter
\newrefcontext[sorting=nyt]
to be on the safe side if there are citations after the bibliography.
Hints and Caveats
Some more explanation since this comes up more often.
biblatex
does not allow the sorting
option for \printbibliography
any more. It was removed because it could lead to weird sorting results.
Instead, now you use 'refcontexts' to control sorting. A refcontext controls sorting
, labelprefix
and sortingnamekeytemplate
and a few other things (possible more in the future).
An entry can appear in different refcontexts and any extra label data (extradate
, extraalpha
) will be recalculated based on the specific details (e.g. sorting) for each refcontext.
This can lead to slightly counter-intuitive results in very contrived examples because the sort order may be determined by data that is invisible in the citation itself and those data leads to different sorting results in different schemes.
Here is an admittedly very artificial example that shows this behaviour with your set-up. It can be much easier to achieve such an effect with other pairings of sort schemes. The trick here was that nyt
considers the volume
for sorting while ynt
does not.
\documentclass{article}
\usepackage[backend=biber, style=authoryear, sorting=ynt, sortcites]{biblatex}
\usepackage{hyperref}
\begin{filecontents}{\jobname.bib}
@book{one,
author = {Elk, Anne},
title = {Title},
volume = {1},
note = {sorts first in ynt},
}
@book{two,
author = {Elk, Anne},
title = {Title},
note = {sorts first in nyt},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\autocite{one,two} \autocite{two,one}
\begin{refcontext}[sorting=nyt]
\printbibliography[title={\refname{} (sorting \texttt{nyt})}]
\end{refcontext}
\end{document}
sorting
option has been moved from\printbibliography
to so called 'refcontexts'. See Biblatex order of entries in a multi-citation. And the default is that all citations obey the refcontext they were last printed in the bibliography. So simply using a globalsorting
that contradicts the\printbibliography
'srefcontext
'ssorting
does not worksortcites=false
and manually sorting references within citation... but I wanted to be lazy and make (Bib)LaTeX do it for me! | Just to be sure to understand your previous comment: the sorting scheme chosen, is the one of therefcontext
selected whenprintbibliography
is called and not at the time of the\cite
command, right? (I tried to add\newrefcontext[sorting=ynt]
right after\begin{document}
+ what I added in my P.S, but it indeed doesn't work.)\printbibliography
. There are ways to manually assign the refcontext (i.e. override the 'use the refcontext of the last bibliography' rule). But you need to be careful about potentially different extrayears.