# Unexpected behaviour with sorting option, multiple ref context and biblist (biblatex 3.0)

I have a large bibliography file where the vast majority of entries are annotated (and annotations can (and do) contain \cite commands).

I have to produce a list of the annotated entries displaying the tile and the notes, and these entries should be listed in reverse chronological order (and grouped by year).

At the end I have to create a standard bibliography including the annotated entries, the entries cited in the annotations, and eventually crossref entries). The bibliography is in standard numeric format and in alphabetic order.

For the list of the annotated entries I can use a biblist (with appropriate filters, and a special driver for it):

\renewcommand{\thesubsection}{\arabic{subsection}}

\DeclareBibliographyDriver{ggtype}{%
\ifnumless{\thefield{year}}{\value{anno}}
{\section*{\printfield{year}}
\setcounter{subsection}{0}
\setcounter{anno}{\thefield{year}}}
{}
\subsection[]{\thefield{title}}
\printfield{note} \printfield{year}
\cite{\thefield{entrykey}}
}

\DeclareBibliographyCategory{exclude}

\DeclareBiblistFilter{ggtype}{
\filter[type=field,filter=note]
}

\defbibenvironment{ggtype}
{\newrefcontext[sorting=nty]} % this line is for biblatex 3.0, biber 2.0
%{} % this line is for biblatex 2.9, biber 1.9
{}
{}

\newcounter{anno}
\setcounter{anno}{2016}


The idea is that I process the entries in two rounds. In the first round I use \nocite{*} to include all entries in the bibtex file, in the second round the entries are taken from information in the biblist (the drive include a command to ensure self-citation (the \cite{\thefield{entrykey}} at the end of the definition of the biblist driver) and the \nocite{*} is removed. I use \IfFileExists{\jobname.bbl}{}{\nocite{*}} to achieve this.

With biblatex 2.9 and biber 1.9. I can use the following schema

\begin{document}

\IfFileExists{\jobname.bbl}{}{\nocite{*}}

\printbibliography[sorting=nyt]
\end{document}


and then use the follow workflow: latex->biber->latex->biber->latex.

Biblatex 3.0 and biber 2.0 replaced the sorting option of \printbibliography, \printbiblist by "reference contexts". Accordingly, I the schema turns out to be:

\begin{document}

\newrefcontext[sorting=ydnt]
\IfFileExists{\jobname.bbl}{}{\nocite{*}}

\printbibliography
\end{document}


and also note the \newrefcontext in the first argument of \definebibenvironment.

I can use the same workflow as the one used for biblatex 2.9.

Here is the "unexpected behaviour" part. If I use

\usepackage[sorting=nty]{biblatex}


then, the workflow fails. The biblist is not printed in the second latex run, and no citations in the second round, and biber complains that there are no citations. Notice that the sorting=nty is useless in this case (so the solution is do not use it), it is harmless with biblatex 2.9 biber 1.9, but problematic with biblatex 3.0 biber 2.0.

Also, after the first round, the bbl file is generated correctly and it is not empty.

The issue was reported to the biblatex developers but they ask to post a question to this site (and to gather ideas from other people). One suggestion was to include \nocite{*} in the second round otherwise this won't be written in the .bcf and biber will not look for anything. However, \cite should be issued inside the biblist. While this suggestion works for the MWE (see blow for the full MWE), for the project I work on, it requires an additional latex->biber roundtrip.

So the question is whether the behaviour with the additional (and useless) sorting option is the expected one or not.

\documentclass{article}

\usepackage[backend=biber
sorting=nyt, % this is the problematic line; commenting it solves the problem.
]{biblatex}
\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@book{first,
title = {First Title},
author = {Author, Author},
year = 2015,
note = {note}
}
@book{second,
title = {Second Title},
author = {Duthor, Duthor},
year = 2015,
note = {note}
}
@book{third,
title = {Third Title},
author = {Buthor, Buthor},
year = 2014,
note = {note}
}
@book{fourth,
title = {Fourth Title},
author = {Cuthor, Cuthor},
year = 2014,
note = {note \cite{seventh}}
}
@book{fifth,
title = {Fifth Title},
author = {Euthor, Euthor},
year = 2014,
}
@book{sixth,
title = {Sixth Title},
author = {Futhor, Futhor},
year = 2015,
note = {note}
}
@book{seventh,
title = {Seventh Title},
author = {Guthor, Guthor},
year = 2014,
}
\end{filecontents}

\renewcommand{\thesubsection}{\arabic{subsection}}

\DeclareBibliographyDriver{ggtype}{%
\ifnumless{\thefield{year}}{\value{anno}}
{\section*{\printfield{year}}
\setcounter{subsection}{0}
\setcounter{anno}{\thefield{year}}}
{}
\subsection[]{\thefield{title}}
\printfield{note} \printfield{year}
\cite{\thefield{entrykey}}
}

\DeclareBibliographyCategory{exclude}

\DeclareBiblistFilter{ggtype}{
\filter[type=field,filter=note]
}

\defbibenvironment{ggtype}
% comment/uncomment the following wto line for biblatex 3.0 and 2.9
{\newrefcontext[sorting=nty]} % 3.0
%{} % 2.9
{}
{}

\newcounter{anno}
\setcounter{anno}{2016}

\begin{document}

% comment /uncomment the following line for biblatex 2.9/3.0
\newrefcontext[sorting=ydnt] % 3.0

\IfFileExists{\jobname.bbl}{}{\nocite{*}}

% comment the following two lines for biblatex 2.9