4

I stumbled upon a problem where I have only the citation key in the list of figures when using the packages biblatex and siunitx at the same time with ref sections.

If you compile the working MWE just below, you get this in the figures' captions

  • Figure 1 caption when siunitx is commented
  • Figure 2 caption when siunitx is commented

And you get a correct list of figures at the end:

  • List of figures when siunitx is commented

But if you uncomment the \usepackage{siunitx} line, you get the same thing in the figures' captions, but in the list of figures, you only get the citation key..

  • List of figures when using siunitx

Any idea on how to get the list of figures working like in the first example, while using the siunitx package?

Thank you.

Tex file : main.tex

\documentclass[12pt, a4paper]{book}

\usepackage{caption} \usepackage{lipsum} \usepackage{siunitx}

\usepackage{biblatex}

\addbibresource{biblatex-examples.bib}

\usepackage{hyperref}

\begin{document}

\begin{refsection}

\begin{figure}[htbp] \centering \rule{2cm}{2cm} \caption{The is the first caption \protect{\autocite{bertram}}} \end{figure}

\printbibliography

\end{refsection}

\begin{refsection} \newpage \lipsum[2] \autocite{doody}

\begin{figure}[htbp] \centering \rule{2cm}{2cm} \caption{The is the second caption \protect{\autocite{aristotle:anima, doody}}} \end{figure}

\printbibliography

\end{refsection}

\clearpage \listoffigures

\end{document}

  • PS : I'm not using siunitx in this MWE, but in my actual projet, i do need it.
  • PS2: I'm compiling on Overleaf.
  • Edit : I saw the question at biblatex combined with refsection and List of Tables but it is without answer, and it does not cover the siunitx package part..
  • Edit 2 : I adapted the MWE to not depend on images
clapsus
  • 143
  • 1
    Interesting question! A first look suggests the .lof looks different when siunitx is loaded: It is missing the \defcounter {refsection}{1}\relax lines that biblatex patches in. But I'm not sure why. Will have to investigate that later... – moewe Mar 22 '21 at 17:01
  • 1
    Unrelated, note that you can make this into a single mwe by adding the bibtex data via the filecontents env in the preamble. It takes the filename to be created as its mandatory argument. Additionally, please don't refer to files we do not have access to (the image), you can use \rule{5cm}{5cm} instead – daleif Mar 22 '21 at 17:07
  • @moewe biblatex adds stuff to \addtocontents at the end of the preamble, and siunitx redefines it at begin document. – daleif Mar 22 '21 at 17:17
  • 1
    @daleif thank you for your advice regarding the MWE, i adapted it and removed the images, the graphicx and float packages that were not relevant to the problem, and i used biblatex-examples – clapsus Mar 25 '21 at 08:34

1 Answers1

3

Update

biblatex switched to an entirely different way of dealing with .lof, .lot etc. files in v3.17. The MWE should now work as desired.

If you are having a similar problem, update your system thoroughly and make sure you have got at least biblatex v3.17. If the problem persists, open an issue at https://github.com/plk/biblatex/issues/.

Some background for the issue can be found at https://github.com/plk/biblatex/issues/1116.

The answer below is kept for historic reasons. It will probably not work as intended in current versions of biblatex and it is definitely not needed.


Old answer

As daleif points out in the comments, biblatex patches \addtocontents in an \AtEndPreamble hook, but then siunitx redefines \addtocontents in an \AtBeginDocument hook, which also overwrites biblatex's patch.

The following fix combines both biblatex's and siunitx' changes to \addtocontents and comes in after both definitions.

\documentclass[12pt, a4paper]{book}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{siunitx}
\usepackage{biblatex}
\usepackage{hyperref}

\addbibresource{biblatex-examples.bib}

\makeatletter \ExplSyntaxOn \AtBeginDocument { \cs_set:Npn \addtocontents #1#2 { \protected@write @auxout { \cs_set_eq:NN \label \use_none:n \cs_set_eq:NN \index \use_none:n \cs_set_eq:NN \glossary \use_none:n \seq_map_inline:Nn \l_siunitx_unit_symbolic_seq { __siunitx_contents_add:N ##1 } } { \token_to_str:N @writefile {#1} {\defcounter{refsection}{\the\c@refsection}\relax} \token_to_str:N @writefile {#1} {#2} } } } \ExplSyntaxOff \makeatother

\begin{document} \begin{refsection} \begin{figure}[htbp] \centering \includegraphics[width=0.2\textwidth]{example-image} \caption{The is the first caption \autocite{bertram}} \end{figure}

\printbibliography \end{refsection}

\clearpage \begin{refsection} \lipsum[2] \autocite{doody}

\begin{figure}[htbp] \centering \includegraphics[width=0.2\textwidth]{example-image} \caption{The is the second caption \autocite{aristotle:anima, doody}} \end{figure}

\printbibliography \end{refsection}

\clearpage \listoffigures \end{document}

LoF with citation numbers.

moewe
  • 175,683