0

I imagine this question has already been posted and answered, but I can't figure out the threads about this issue. Sorry for the possible duplication.

I use biblatex with Biber.

When using multiple citations, i.e. by the use of \parencites, the citations appear in the pdf in the same order I entered them. Can't Biber automatically sort them alphabetically (and then in reverse chronological order if there are more references to the same author)?

moewe suggested this solution: Biblatex: Sorting citations in qualified citation list \parencites but I seems rather complicated. Will it solve the problem? Is there a simpler work-around?

MWEB:

\documentclass{report}
\usepackage[a4paper,bindingoffset=0.5cm, left=2.6cm,right=2.6cm,top=2.6cm,bottom=3cm, footskip=.67cm]{geometry}
\usepackage{gensymb}
\usepackage[backend=biber,maxbibnames=99,date=year,sortlocale=danish,firstinits=true,style=authoryear-icomp,dashed=false,doi=false,isbn=false,url=true,]{biblatex}
\addbibresource{ex.bib}

\begin{document}
The references are not ordered alphabetically \parencites{stigler1999}{bahn2017c}{bahn2017a}.
References the same article are not sorted by the order of page numbers \parencites[31]{bahn2017a}[1]{bahn2017a}
\end{document}

BIB:

@book{stigler1999,
  location = {{New York}},
  title = {The {{Teaching Gap}}: {{Best Ideas}} from the {{World}}'s {{Teachers}} for {{Improving Education}} in the {{Classroom}}.},
  publisher = {{The Free Press}},
  date = {1999},
  author = {Stigler, James W. and Hiebert, James}
}

@article{bahn2017a,
  title = {An Experiment with {{Open}}-Ended {{Approach}} in Grade Four Probability Teaching},
  journaltitle = {Recherches en Didactique des Mathématiques},
  date = {2017-06},
  author = {Bahn, Jacob},
  file = {/home/jb/.mozilla/firefox/mwad0hks.default/zotero/storage/LN55IYG2/Bahn - 2017 - An experiment with Open-ended Approach in grade fo.pdf},
  pubstate = {revision}
}

@article{bahn2017c,
  title = {Evolution of Teachers' Anticipation of Didactical Situations in the Course of Three Lesson Studies},
  journaltitle = {Annales de Didactique et de Sciences Cognitives},
  date = {2017-10},
  author = {Bahn, Jacob},
  file = {/home/jb/.mozilla/firefox/mwad0hks.default/zotero/storage/Y3G88PIA/Bahn - 2017 - Evolution of teachers' anticipation of didactical .pdf},
  pubstate = {review}
}
  • 1
    No, 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 – moewe Jul 14 '18 at 14:50
  • I updated the better answer at tex.stackexchange.com/q/65809/35864 – moewe Jul 14 '18 at 14:52
  • @moewe: Do you prefer \cite over \parencite? – jbahn Jul 14 '18 at 18:35
  • Huh? As a matter of fact I try to use \autocite as much as possible. Was that a roundabout way to get at tex.stackexchange.com/q/271307/35864? – moewe Jul 14 '18 at 18:43
  • Did the linked question help you? If so, I would vote to close this as a duplicate. If it does not work for you, please edit your question with more details and an explanation why it does not work (ideally with an MWE that shows the problem). – moewe Jul 16 '18 at 9:38
1

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

  1. 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.
  2. 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 theoretically possible, see Biblatex: how to automatically sort citation by year (sortcites=ynt) when references are sorted by name (sorting=nyt), but it is not a good idea. The way sorting currently works means that you have to switch refcontexts between the citations and the bibliography, since sorting is tied to refcontexts. But since refcontexts control not only the sorting, but with it also disambiguation letters (Bahn 2007a, Bahn 2007b etc.), you can be left with undesirable and very subtly incorrect references. See the example and explanation in the linked answer.

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}.

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.