plk / biblatex

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

References in listof not handled anymore #1220

Open ArchangeGabriel opened 2 years ago

ArchangeGabriel commented 2 years ago

Doing my usual regression test, I’ve seen a behaviour change with the latest TeX Live update on my system (which contains upgrade package biblatex 57272 -> 61868, so I guess this is 3.16 to 3.17). I’m not entirely sure that the issue is in biblatex itself, but I think that you should be able to determine that more easily than me.

The (almost) MWE is the following:

\documentclass{article}

\usepackage{biblatex}

\begin{filecontents}{\jobname.bib}
@article{BaadeZwicky1934a,
   author = {Baade, W. and Zwicky, F.},
    title = {On Super-novae},
  journal = {Proceedings of the National Academy of Science},
     year = 1934,
    month = may,
   volume = 20,
   number = 5,
    pages = {254-259},
      doi = {10.1073/pnas.20.5.254}
}
@article{BaadeZwicky1934b,
   author = {Baade, W. and Zwicky, F.},
    title = {Cosmic Rays from Super-novae},
  journal = {Proceedings of the National Academy of Science},
     year = 1934,
    month = may,
   volume = 20, 
   number = 5,
    pages = {259-263},
      doi = {10.1073/pnas.20.5.259}
}
\end{filecontents}

\addbibresource{\jobname.bib}

\usepackage{graphicx}

\begin{document}

\textcite{BaadeZwicky1934a}

\begin{figure}
    \includegraphics{example-image}
    \caption[Test in lof \textcite{BaadeZwicky1934b}]{
        Some figure.
    }    
\end{figure}

\listoffigures

\printbibliography

\end{document}

The first reference works correctly, but the one in the listoffigures does not (wherever the \listoffigures is placed). And you don’t even get a warning of undefined reference, but at this point I guess this is expected?

Note: this is not limited to listoffigures, I just choose that one to illustrate, but to every listof systems (so tables, but also customs ones —I have one for image credits, and that’s the one I spotted the issue in initially).

moewew commented 2 years ago

Thank you very much for reporting this issue.

I ran the example with Overleaf's TeX Live 2021, which has v3.16 and got the same output that I get with 3.17. Are you sure this is a recent change in behaviour? Anyway, with Overleaf's TeX Live 2020 (biblatex v3.14) the example compiles to the expected output, so it is fair to say this changed at some point.

As far as I can see, however, this is "by design". \listof... are exempted from "cite requests", meaning they don't actively ask Biber to look up the relevant key, so as to not mess up "unsorted sorting" (sorting=none,). You have to explicitly \cite (or \nocite) all entries you are citing within \listof...s outside of such a list. See also https://tex.stackexchange.com/q/541742/35864 for a slightly longer discussion and a workaround.

ArchangeGabriel commented 2 years ago

I ran the example with Overleaf's TeX Live 2021, which has v3.16 and got the same output that I get with 3.17. Are you sure this is a recent change in behaviour? Anyway, with Overleaf's TeX Live 2020 (biblatex v3.14) the example compiles to the expected output, so it is fair to say this changed at some point.

I rebuild my test document each time TeX Live is updated on my system, but it’s possible that I did not clean aux files last time(s?) and it somehow stuck for sometime… I’ll be more attentive to do that in future regression tests.

As far as I can see, however, this is "by design". \listof... are exempted from "cite requests", meaning they don't actively ask Biber to look up the relevant key, so as to not mess up "unsorted sorting" (sorting=none,). You have to explicitly \cite (or \nocite) all entries you are citing within \listof...s outside of such a list. See also https://tex.stackexchange.com/q/541742/35864 for a slightly longer discussion and a workaround.

OK thanks, using \nocite partially solves it. Partially, because there is another issue: with this change, they are also no backref in the bibliography towards the listof citations… So in my bibliography, the affected article appeared to be cited nowhere, and others that are cited in both text and listof have only their text appearance listed, not their listof ones.

Unless you have a workaround for this too, that looks as an issue that needs fixing. The easiest fix to me would be to make using the listof an optional behaviour that defaults to on unless using sorting=none.

moewew commented 2 years ago

Oh right, with biblatex v3.17 there is actually a much more elegant method to work around this.

biblatex now essentially executes a few "resets" before every \...cite command in .lof/... files.

https://github.com/plk/biblatex/blob/433e907befede89ded13c005ffe5fe6b8a1c0da7/tex/latex/biblatex/biblatex.sty#L645-L658

These resets disable the cite request and also disable backreferences and other citation tracking.

You can uncomment the resets you don't like

\documentclass{article}

\usepackage{graphicx}

\usepackage[backref=true]{biblatex}

\makeatletter
\protected\def\blx@tocontentsinit#1{%
  %\boolfalse{citerequest}%
  \boolfalse{citetracker}%
  \boolfalse{pagetracker}%
  %\boolfalse{backtracker}%
  \defcounter{refsection}{#1}}
\makeatother

\begin{filecontents}{\jobname.bib}
@article{BaadeZwicky1934a,
   author = {Baade, W. and Zwicky, F.},
    title = {On Super-novae},
  journal = {Proceedings of the National Academy of Science},
     year = 1934,
    month = may,
   volume = 20,
   number = 5,
    pages = {254-259},
      doi = {10.1073/pnas.20.5.254}
}
@article{BaadeZwicky1934b,
   author = {Baade, W. and Zwicky, F.},
    title = {Cosmic Rays from Super-novae},
  journal = {Proceedings of the National Academy of Science},
     year = 1934,
    month = may,
   volume = 20, 
   number = 5,
    pages = {259-263},
      doi = {10.1073/pnas.20.5.259}
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\textcite{BaadeZwicky1934a}

\begin{figure}
    \includegraphics{example-image}
    \caption[Test in lof \textcite{BaadeZwicky1934b}]{
        Some figure.
    }    
\end{figure}

\listoffigures

\printbibliography
\end{document}

It would be nicer to give users a way to modify these resets without having to resort to redefining internal commands, so I will think about an interface for this.

ArchangeGabriel commented 2 years ago

citetracker and pagetracker are already false by default, right? So I guess I can keep just the defcounter part. At least that seems to work. :)

moewew commented 2 years ago

citetracker and pagetracker are already false by default, right?

That will depend on the style you choose. In the example they are both false, yes. But with style=authoryear-ibid, for example they'd be both true.

ArchangeGabriel commented 2 years ago

I’m using style=authoryear-comp. I did not see a difference in any case, so that’s good for me, thanks. An interface for this would be nicer, but on my side at least I have a workaround now, so I’m good. :)