0

I would like to sort my bibliography alphabetically, but a list of citations in-text by year.

This question is about the same problem. However, the answer given relies on wrapping \printbibliography in a refcontext to change the sorting:

\begin{refcontext}[sorting=nyt]
\printbibliography
\end{refcontext}

I am writing a custom biblatex style for my university. I would like this behaviour to be the default, without the user of the style needing to change sorting within the document.

What do I need to include in the .bbx and/or .cbx files to achieve this?

Edit:

I can achieve this using:

\NewCommandCopy{\oldprintbibliography}{\printbibliography}
\renewcommand{\printbibliography}{
\begin{refcontext}[sorting=nyt]
  \oldprintbibliography
\end{refcontext}
}

But this has the serious drawback that the user is then not able (without errors) to wrap \printbibliography in their own refcontext.

  • Define a user-command in your style that prints both? – Cicada Jun 15 '22 at 15:31
  • @Cicada Do you mean \renewcommand{\printbibliography} ? – Heisenbugs Jun 15 '22 at 16:28
  • Both ref contexts/commands. In a wrapper. So user types one command. – Cicada Jun 15 '22 at 16:32
  • @Cicada The standard command to print the bibliography is \printbibliography, so I would want that to stay the same and not use some custom \printourunibib. So are you suggesting renewing this command? I just assumed there was some way to set the sorting, which is why I asked the question. – Heisenbugs Jun 15 '22 at 16:35
  • \renewcommand{\printbibliography} could be a wrapper, yes. But sorting is attached to styles when not using ref contexts - are you using separate bibstyle/citestyle options? – Cicada Jun 15 '22 at 16:43
  • Where is the dividing line between what the user can/cannot adjust going to be? Solution flows from there. – Cicada Jun 15 '22 at 16:46
  • @Cicada My goal is that the user can adjust anything they want, but that the default sorting is as described without them having to do anything other than setting style=unistyle. What do you mean by using separate bibstyle/citestyle? Do you mean like setting bibstyle=unistyle,citestyle=unistyle? – Heisenbugs Jun 15 '22 at 16:49

1 Answers1

2

If you use biblatex v3.18b (2022-07-12) or above you can use the new \localrefcontext and \GenRefcontextData to switch to a different reference context (e.g. sorting) in citations as follows

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

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

\AtBeginRefsection{\GenRefcontextData{sorting=ynt}} \AtEveryCite{\localrefcontext[sorting=ynt]}

\addbibresource{biblatex-examples.bib}

\begin{document} Lorem \autocite{sigfridsson,worman,nussbaum,geer}

\printbibliography \end{document}

Lorem (Nussbaum 1978; Geer 1985; Sigfridsson and Ryde 1998; Worman 2002)
Geer, Ingrid de (1985). ‘Earl, Saint, Bishop, Skald – and Music. The Orkney Earldom of the Twelfth Century. A Musicological Study’. PhD thesis. Uppsala: Uppsala Universitet.
Nussbaum, Martha (1978). Aristotle’s ‘De Motu Animalium’. Princeton: Princeton University Press.
Sigfridsson, Emma and Ulf Ryde (1998). ‘Comparison of methods for deriving atomic charges from the electrostatic potential and moments’. In: Journal of Computational Chemistry 19.4, pp. 377–395. doi: 10.1002/(SICI)1096-987X(199803)19:4<377::AID-JCC1>3.0.CO;2-P.
Worman, Nancy (2002). The Cast of Character. Style in Greek Literature. Austin: University of Texas Press.

The

\AtBeginRefsection{\GenRefcontextData{sorting=ynt}}

makes sure that each refcontext your document uses also generates one with ynt sorting.

The

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

moewe
  • 175,683