There are several issues at play here. The by far more important and bigger issue is that of sorting multicite commands across different arguments.
Sorting multicite
The difficulties
Due to the way the multicite commands are implemented, biblatex
can't sort the citation list created by those commands out of the box.
A cunning trick allows for very simple sorting of single-cite commands, but this is not easily available here. The trick works as follows: biblatex
has a list of all entry keys in sort order, it also has a list of entries requested in this citation. biblatex
runs through the sorted list of all entries and adds those entries to a new list (that bit is simplified) that are in the list of cited entries. That leaves a list of sorted entries for this citation.
If you use a style (e.g. style=authoryear-icomp
) that sorts citations and you cite with pre- and postnotes
\cite[cf.][67]{worman,sigfridsson}
you will see the warning
Package biblatex Warning: Package option 'sortcites' enabled.
(biblatex) Verify postnote placement on input line 14.
This shows the drawback of this simple sorting approach: The pre- and postnotes are still stuck to the front and back of the citation. They are not tied to specific entries.
This is different for the multicite commands
\cite[cf.][67]{worman}[but][380]{sigfridsson}
here the pre- and postnotes are tied to their specific entries.
The implementation of the multicite command works in a way that each 'chunk' of optional and mandatory arguments [<pre>][<post>]{<key>}
is essentially parsed separately. These chunks are then glued together into one long expression not knowing the actual contents of the chunks.
Naively one could try to sort the chunks before gluing them together into the final expression. This could work, but there are two potential hurdles
- The pre- and postnotes are either tied to a specific chunk or to a specific entry and must sort with it. That means in all likeliness that they need to be saved temporarily.
The sorting of chunks with several entry keys is not clear. While it is simple to determine the desired sorted output of
\parencites[6]{sortorder3}[5]{sortorder1}[9]{sortorder2}
namely
\parencites[5]{sortorder1}[9]{sortorder2}[6]{sortorder3}
this is not so easy with
\parencites[8]{sortorder4,sortorder2}[3]{sortorder3}[1]{sortorder1}
is the expected output
\parencites[1]{sortorder1}[8]{sortorder2,sortorder4}[3]{sortorder3}
or
\parencites[1]{sortorder1}[8]{sortorder2}[3]{sortorder3}{sortorder4}
And what would you expect for
\parencites[1]{sortorder1,sortorder2}[3]{sortorder1,sortorder3}
That is to say as soon as one of the {<key>}
arguments itself contains multiple entry keys, the expected output is not immediately clear.
While the cases in item 2 seem far fetched and unusual since the whole point of multicite commands is to fix the pre and postnotes per entry, the syntax with several keys per mandatory arguments is valid and must continue to work.
Audrey's answer
Audrey has provided an answer that does sort multicite citations in Sorting citations using \cites command in biblatex (a straightforward extension for cite commands other than \cites
is at Biblatex: Sorting citations in qualified citation list \parencites). Her solution uses a two-pass scheme to sort the entries. That allows us to collect a list of cited keys, save the corresponding pre- and postnotes and sort the keys afterwards. A related two-pass scheme is implemented for \textcite
in some standard citation styles.
Two-pass citation commands have some structural complications that can be worked around (at least as far as I am aware the \textcite
commands of the standard styles all work fine, even though some of them use this complicated structure). But more importantly they need support by the bibliography/citation styles. That means that it is going to be quite hard bordering on the impossible to implement this in a way that all styles can benefit from the sorting without them having to do anything for that while at the same time making sure that nothing breaks badly. See also https://github.com/plk/biblatex/issues/214.
Audrey's answer has found an adequate way to address both issue 1 and 2: Pre- and postnotes are saved per entry as they would appear in the output after sorting
\cites[cf.][45]{sigfridsson,worman}
Would assign "cf." as prenote to sigfridsson
and 45
as postnote to worman
(assuming worman
sorts after sigfridsson
!).
And no structure is preserved when sorting, all chunks are broken up into single entries before sorting.
The solution as presented currently has some shortcomings. In particular the citation trackers get confused by the two-pass structure of the citation commands. This should be fixable in a way similar to the standard style \textcite
commands, but I have not yet had a look to see if it is easily fixable. More importantly though an entry can only be cited once per \cites
, so your \parencites[31]{bahn2017a}[1]{bahn2017a}
example would fall flat. This is inherent to the strategy chosen to address issue 1 above. It could possibly fixed with a more complicated structure, but that would require more variables and more variable storage as well as proper clean-up.
In fact I believe it would not be entirely impossible to modify the internals to sort multicite commands automatically. But every simple solution I pondered fell flat when confronted with one of the two issues listed above. In particular the sorting done on the biblatex
side must be simple and should not involve implementing a classical sort algorithm.
Sorting by postnote
You also seem to be interested in sorting multicite commands not only by entry key, but also by postnote argument to break a tie.
That also poses new difficulties. biblatex
relies on the backend (Biber or the legacy backend BibTeX) for sorting. In particular the sorting is determined for the entire document and fixed. The postnote
argument, however, is local to the document and not known to the backend, so it can't be easily used for sorting. Additionally biblatex
only knows the concept of sorting entries, not entries+extra data. So in all likeliness the additional sorting would have to be implemented in LaTeX. There is a good reason why traditionally sorting was taken over by external programmes (BibTeX, Biber, makeindex
, xindy
, ...) and not implemented in LaTeX itself. The advent of Unicode has not made sorting less complex, and while there are some promising things possible in LaTeX3, I'm not sure that they do Unicode sorting and collation at the moment. Of course sorting plain numbers is much easier than sorting arbitrary strings.
Different sorting for bibliography and citations
A minor issue is that as I understand it you want to sort your citations differently from your bibliography (citations descending, bibliography ascending). This is possible, see Biblatex: how to automatically sort citation by year (sortcites=ynt) when references are sorted by name (sorting=nyt), but there are some subtle points there.
To your explicit questions
To answer your explicit questions. As far as I know, Audrey's answer in Sorting citations using \cites command in biblatex and my trivial extension in Biblatex: Sorting citations in qualified citation list \parencites are indeed the closest you can get to a sorted multicite list at the moment. The solution is not perfect and you may experience a few rough patches here and there, some of which can probably be fixed fairly easily if you ask a question in this site - others may be more fundamental and harder to resolve.
The answer does not have a good solution for sorting citations differently from the bibliography, but that is a general problem as outlined above. It also can not deal with several citations to the same entry at once, i.e. your second example \parencites[31]{bahn2017a}[1]{bahn2017a}
.
biblatex
does not sort the different arguments of multicite commands. This can be changed, if you need it. See tex.stackexchange.com/q/420394/35864\autocite
as much as possible. Was that a roundabout way to get at tex.stackexchange.com/q/271307/35864?