3

I am trying to print out the reference list automatically at the end of the document with \AtEndDocument{\printbibliography}, but I end up with

Package biblatex Warning: Please rerun LaTeX.

no matter how many times I run LaTeX. Prior to using \AtEndDocument, the biblatex code says

Here we mustn't change the checksum if we used localnumbers from the .aux file as this means that deferred numbering is complete. Otherwise we get in an endless rerun loop because the checksum due to number changes is always different.

so presumably I need to either hack where I insert \printbibliography or potentially call some of the biblatex code again after I print the bibliography.

While the easiest solution is to probably call \AtEndDocument{\printbibliography} before \usepackage{biblatex}, I would rather avoid that order dependency. How can I robustly get the bibliography to print at the end of the document regardless of if I run the code before or after I load the biblatex package.

\documentclass{article}
\usepackage{biblatex}
\addbibresource{biblatex-examples.bib}
\AtEndDocument{\printbibliography}
\begin{document}
  \autocite{aksin}
\end{document}
3
  • biblatex does some housekeeping in \AtEndDocument, you should really get your \printbibliography in before then. Unfortunately, the \AtEndDocument code from biblatex is sprinkled throughout biblatex.sty and not collected in a hook of its own, so you can't easily get past biblatex's stuff. I guess it might be possible to subvert \AtBeginDocument for biblatex, but I believe that the easiest solution is to issue \AtEndDocument{\printbibliography} before you load biblatex.
    – moewe
    Jan 9 '19 at 16:35
  • Mhh I wouldn't rely on the exact internals of when biblatex starts to do its \AtEndDocument stuff. That might change. But the \preto sounds like a plan (assuming you have nothing else in \AtEndDocument that would have to happen before \printbibliography).
    – moewe
    Jan 9 '19 at 16:48
  • 1
    Thanks for the answer. If you don't mind terribly, I would like to let my first comment live (even though it turned out that my belief was mistaken). I don't feel that strongly about the second comment, but would also like to opt not to delete it at the moment.
    – moewe
    Jan 10 '19 at 19:58
3

Patching into \@enddocumenthook (the macro that the argument of \AtEndDocument is appended to) by looking for the biblatex housekeeping is problematic since the housekeeping is internal code and subject to change. Instead, I decided to prepend \printbibliography to \@enddocumenthook with \preto from the etoolbox package. This does not depend on when biblatex is loaded as it always goes in the front. If something else is trying to do something before \printbibliography, then it could cause problems.

\documentclass{article}
\usepackage{biblatex}
\usepackage{etoolbox}
\addbibresource{biblatex-examples.bib}
\makeatletter
\preto{\@enddocumenthook}{\printbibliography}
\makeatother
\begin{document}
  \autocite{aksin}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.