Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit citations take precedence over \nocite{*} when sorting=none #404

Closed
marcvinyals opened this issue Mar 27, 2022 · 20 comments
Closed

Comments

@marcvinyals
Copy link

I am using biblatex with the none sorting option, and a document that starts with a \nocite{*} command and contains a few explicit citations using \cite later on. With biber <= 2.14 later explicit citations do not affect the bibliography order, however with biber >= 2.15 explicit citations always appear before implicit citations. Here is a MWE:

\documentclass{article}

\begin{filecontents}{\jobname.bib}
@misc{ref1,
  author = {Author1},
  title = {Title1},
}
@misc{ref2,
  author = {Author2},
  title = {Title2},
}
\end{filecontents}

\usepackage[backend=biber,style=numeric,sorting=none]{biblatex}
\addbibresource{\jobname.bib}

\begin{document}

\nocite{*}

Hello~\cite{ref2}.

\printbibliography

\end{document}

This results in

Hello [2].
References
[1]Author1. Title1.
[2]Author2. Title2.

with biber <= 2.14 but

Hello [1].
References
[1]Author2. Title2.
[2]Author1. Title1.

with biber >= 2.15. In case it helps, using git bisect I was able to trace this back to commit afa8173, and indeed this seems to be related to the discussion about the order of \cite and nocite{*} in #319.

@plk
Copy link
Owner

plk commented Mar 27, 2022

Yes, this was done as there needed to be some determinism. \nocite citations don't really have a "place" in the document so I assumed we could just assume they occurred at the end in unsorted citation sorting schemes. I realise that this changes the document behaviour in this case but is it otherwise a problem?

@marcvinyals
Copy link
Author

It is a problem in my use case, where I want bibliography entries to appear in the same order as in the bib file, but I can fix that by adding a custom sorting key, so it is not a big deal. However it is inconsistent with the biblatex documentation; version 3.17 section 3.9.6 says that "For the purposes of ordering citations by appearance \nocite will behave like all other cite commands" (or perhaps I misunderstood that line and it was only meant to apply to \nocite{key}).

@plk
Copy link
Owner

plk commented Mar 28, 2022

The problem here is that the current behaviour was designed to cope with the situation where someone does:

\cite{b,a}
\nocite{*}

and where a comes before b in the .bib. In this case, we want the \cite order to override the \nocite order but in your case, you want the \nocite order to override the \cite order ...

@marcvinyals
Copy link
Author

I would expect your example to produce (b,a), no matter where a and b appear in the .bib, since they are cited before \nocite, but I would expect

\nocite{*}
\cite{b,a}

to produce (a,b) if a comes before b in the .bib.

@plk
Copy link
Owner

plk commented Mar 31, 2022

\nocite{*} and sorting=none is a special case as this means ".bib order"which, because the order doesn't come from the document but from the bib database. It would be tricky changes in both biblatex and biber to make this work as if it were a citation command with a "location" in the document and so I think we'll likely leave this as a special case that has workarounds.

@moewew
Copy link
Contributor

moewew commented Mar 31, 2022

I'm not a fan of trying to force .bib order, but conceptually I think \nocite should "act" in the place it is called. Since \nocite also just writes to the .bcf Biber already has the order information it needs from the biblatex available. The fact that things used to work as desired (in Biber 2.14) also makes me think that there should be a way on the Biber side to make this work.

@plk
Copy link
Owner

plk commented Mar 31, 2022

I think the 2.14 behaviour was only partially correct. biblatex has a hard-coded order of '0' for \nocite{*} which would need to be changed in order for the .bcf to have the necessary information for biber. Without this change, both:

\nocite{*}
\cite{a}

and

\cite{a}
\nocite{*}

result in the same cite order attribute in the .bcf anyway.

@moewew
Copy link
Contributor

moewew commented Mar 31, 2022

I see, I guess the biblatex changes would be doable, but I have no idea how this looks on the Biber side.

plk added a commit that referenced this issue Apr 1, 2022
plk added a commit to plk/biblatex that referenced this issue Apr 1, 2022
@plk
Copy link
Owner

plk commented Apr 1, 2022

Please try biblatex and biber DEV versions on Sourceforge. Note that:

\cite{b,a}
\nocite{*}

Won't do the same as:

\cite{b}\cite{a}
\nocite{*}

as \cite{x,y} assigns the same citation order to x and y by design so that such cases can be further discriminated by additional sorting options.

@moewew
Copy link
Contributor

moewew commented Apr 3, 2022

That means that

\documentclass{article}

\begin{filecontents}{\jobname.bib}
@misc{ref1,
  author = {Author1},
  title = {Title1},
}
@misc{ref2,
  author = {Author2},
  title = {Title2},
}
\end{filecontents}

\usepackage[backend=biber,style=numeric,sorting=none]{biblatex}
\addbibresource{\jobname.bib}

\begin{document}
Hello~\cite{ref2,ref1}.

%\nocite{*}

\printbibliography
\end{document}

and

\documentclass{article}

\begin{filecontents}{\jobname.bib}
@misc{ref1,
  author = {Author1},
  title = {Title1},
}
@misc{ref2,
  author = {Author2},
  title = {Title2},
}
\end{filecontents}

\usepackage[backend=biber,style=numeric,sorting=none]{biblatex}
\addbibresource{\jobname.bib}

\begin{document}
Hello~\cite{ref2,ref1}.

\nocite{*}

\printbibliography
\end{document}

produce different results. Which is pretty counter-intuitive to me.

I think if there is nothing else to go by

\cite{b,a}
\nocite{*}

and

\cite{b}\cite{a}
\nocite{*}

should result in the same sort order, because citation order is determined first and foremost by cite order (where the second case is "stronger" than the first, but both would still result in b < a) and only then by a fallback such as bib file order.

@plk
Copy link
Owner

plk commented Apr 5, 2022

I'm not sure about this, it is by design that \cite{b,a} is the same "cite order" as \cite{a,b} because this is sometimes useful in sorting templates and you can always get explicit cite order with \cite{b}\cite{a}. We can be more explicit in the docs that "citation order" really does mean the order of \cite* macros with the explicit intention that you can have the "same" citation order by using the same citation macro. I can dig out the justification for this but I do remember that this was all on purpose so that it was possible to differentiate precisely in this way.

@plk
Copy link
Owner

plk commented Jun 20, 2022

Lost track of this - is there still something to do here?

@moewew
Copy link
Contributor

moewew commented Jun 20, 2022

That depends on your feelings towards the example in #404 (comment). I find it extremely confusing that a \nocite{*} would change the sort order in this example. I think the order in the .bib file should be the very last resort, certainly after the order implied by citations in the same \cite call.

@plk
Copy link
Owner

plk commented Jun 20, 2022

I'm really not sure about this. I do like the idea of the semantic difference between \cite{a,b} and \cite{a}\cite{b} as then you have some sort of proximity information when using sorting=none. Might have to leave this one for the next release as it's a fairly esoteric case anyway.

@moewew
Copy link
Contributor

moewew commented Jun 20, 2022

I agree that it is nice to have a difference between \cite{a,b} and \cite{a}\cite{b}, but what I don't like is that in\cite{a,b} the bib file order takes over. I must admit I have not thought this through for other sorting schemes and settings, though.

In principle I'm OK with not resolving this now and leaving it for a future release. But there is the slight risk of annoying users by changing things now and then possibly changing them again in the short or medium term. I guess we have to live with that. It would be unreasonable to put off the release until we've figured this one out. And you are right, it is a fairly niche case anyway.

plk added a commit to plk/biblatex that referenced this issue Jun 21, 2022
plk added a commit that referenced this issue Jun 21, 2022
@plk
Copy link
Owner

plk commented Jun 21, 2022

I see what you mean. I had a look at this and I think I have a general solution now. To make this work properly, we now track the internal order within cite commands as well as the cite order in the refsection. This is output to the .bcf and a new sorting macro \intciteorder is available as a further disambiguation on top of \citeorder. The none sorting scheme now uses this as it is what people expect - it no longer falls back on .bib order for explicit cites and the two examples above now return the same thing.

@moewew
Copy link
Contributor

moewew commented Jun 21, 2022

Looks good to me.

@plk
Copy link
Owner

plk commented Jun 21, 2022

Anything else to do for release of 2.18/3.18 on your end?

@moewew
Copy link
Contributor

moewew commented Jun 21, 2022

I think we're good to go from my side.

@plk
Copy link
Owner

plk commented Jun 21, 2022

Very good, I'll start the process and then afterwards have a look at the multiscript thing.

@plk plk closed this as completed Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants