plk / biblatex

biblatex is a sophisticated bibliography system for LaTeX users. It has considerably more features than traditional bibtex and supports UTF-8
507 stars 115 forks source link

New citation sorting for the references in the text #1275

Closed mapfiable closed 1 year ago

mapfiable commented 1 year ago

When citing multiple referenes at once, I would like to have the option to sort the citations by year-name-title, but not how it is curretly implemented. In the current implementation, ynt is a strict rule, which means that if some author A e.g. published two works some years apart, and a second author B published at some point in between, the the citations of author A will be split, e.g. like so:

(Author et al. 2010; Buther et al. 2012; Author et al. 2015; Cuthor et al. 2016)

I would like a sorting style where the citations are sorted by year first, unless the work is published by the same author, so something like this:

(Author et al. 2010, 2015; Buther et al. 2012; Cuthor et al. 2016)

Especially if you have several works by the same authors that are "interrupted" by other citations, the list will become needlessly long.

moewew commented 1 year ago

I don't think this is possible in the current framework. Currently citation sorting works by looking at a sorted list of all keys (this list is generated by Biber according to the selected sorting scheme). This means that context-dependent sorting is not available. But this needs context-dependent sorting. Specifically, you want

Author 2010, Buther 2012, Cuther 2016

and

Author 2010, 2015, Buther 2012, Cuther 2016

but

Buther 2012, Author 2015, Cuther 2016

Here "Author 2015"'s sorting position changes depending on the presence of Author 2010.

This would require sorting on a per-cite-call basis.

plk commented 1 year ago

This isn't really a coherent sorting scheme and it's more easily dealt with by using separate \cite{} for each author I think.

mapfiable commented 1 year ago

Hi thanks! That seems very complicated in deed. What a shame. It would be still nice to have though....

I tried to solve this by just locally switching so sorting=none, and manually ordering the references in the citation according to my preferences. So I tried doing this, but it doesn't work:

\newcommand{\manualciteorder}[1]{%
\begingroup%
    \newrefcontext[sorting=none]#1%
\endgroup%
}%

Then I noticed in the manual that there is also this \localrefcontext, but I don't understand how I am supposed to use it. It would be great if \localrefcontext is actually used in given the examples. They also some to have some errors.

moewew commented 1 year ago

For your intents and purposes it should be enough to locally disable sortcites.

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[backend=biber, style=authoryear-comp]{biblatex}

\makeatletter
\newcommand*{\DisableSortcites}{%
  \let\blx@thecitesort\blx@citenosort
  \let\blx@thenotecheck\relax
  \boolfalse{sortcites}}
\makeatother

\addbibresource{biblatex-examples.bib}

\begin{document}
Lorem \autocite{knuth:ct:a,sigfridsson,knuth:ct:b}

\begingroup
\DisableSortcites
Ipsum \autocite{knuth:ct:a,sigfridsson,knuth:ct:b}
\endgroup

Dolor \autocite{knuth:ct:a,sigfridsson,knuth:ct:b}

\printbibliography
\end{document}

If that does not help, you really ought to show us a minimal example document of what you are trying. Debugging code snippets without context is always pretty tricky.

mapfiable commented 1 year ago

Thanks a lot! But for some reason, this doesn't work in my case (I'm using the kaobook template). Without even using the command I get the following error: You can't use \spacefactor in vertical mode.

moewew commented 1 year ago

If you are having trouble implementing this suggestion (which works in principle) I suggest you ask a question on TeX.SX or your favourite TeX forum. Be sure to include an example document showing what you tried.

Often the spacefactor error is a sign that something went wrong with \makeatletter...\makeatother. The code I posted really needs these commands around the definition of \newcommand*{\DisableSortcites}. But if you paste it into an existing preamble you need to check if the category code regime works out. If you add a \makeatother in the wrong place, you might get errors.

In any case my experience has been that it's better to stay away from complex templates on GitHub that are scarcely maintained.

mapfiable commented 1 year ago

Thank you for the advice! This allowed me to fix it.