3

I am putting together a MWE for a question about biblatex, and while doing so, I'm at a loss to understand why this simple MWE fails. When running biber, I get the message WARN - I didn't find a database entry for 'smith1983' (section 0). I am running biber v.2.17 in texlive 2022.

\documentclass{article}

\usepackage{biblatex} \usepackage{filecontents} \begin{filecontents}{\jobname.bib} @book{smith1983, AUTHOR = "Harry Smith", TITLE = "My second book", YEAR = "1983"} \end{filecontents} \addbibresource{\jobname.bib}

\begin{document}

\nocite{smith1983}

\printbibliography \end{document}

Sverre
  • 20,729
  • 2
    Works OK for me. Check the .bib file has that entry, and clear all the temp files and do a clean run. – Cicada Jun 02 '22 at 12:16
  • Crystal ball: You had a first version of the file with a different bibkey, compiled it, changed the key, but filecontents nowadays no longer overwrites by default (your example does give a warning of obsolete package), so you are left with the old \jobname.bib. If the crystal ball is correct, try \begin{filecontents}[overwrite]{\jobname.bib} (and let go of the filecontents package as it doesn't serve you much anyway). – gusbrs Jun 02 '22 at 12:57
  • @gusbrs Yes, I've reached a similar conclusion. filecontents is disabled during compiling, so it rather generates a .bib file with the same filename as my .tex file. The problem is that if I append anything to the \jobname.bib in my preamble, this is not appended to the .bib file. So I need to delete the generated .bib file every time I change anything in \jobname.bib. Btw, what should we now use instead of filecontents when creating MWEs for bibliography questions? – Sverre Jun 02 '22 at 13:04
  • 2
    @Sverre It's in the kernel, you can use the environment, just don't need the package. But the syntax is slightly different, just use the [overwrite] argument, as I've said, so you don't need to manually delete anything. – gusbrs Jun 02 '22 at 13:12
  • @gusbrs What I don't understand is that it still won't overwrite the old jobname.bib file, it just overwrites the filename.bib file (which is generated with the same filename as the .tex file). So what is then the purpose of having the \begin{filecontents}{\jobname.bib} and \addbibresource{\jobname.bib} lines? – Sverre Jun 02 '22 at 13:20
  • @Sverre Sorry, I don't understand what you mean there, and can't reproduce. Using the optional argument to filecontents works as described for me here. – gusbrs Jun 02 '22 at 13:22
  • @gusbrs \begin{filecontents}{\jobname.bib} doesn't write a file jobname.bib. – Sverre Jun 02 '22 at 13:40
  • 1
    @Sverre Well, of course not! \jobname is a macro which stores the name of the file being processed... If you really want a file jobname.bib, you should write \begin{filecontents}[overwrite]{jobname.bib}, but you can use any name there. – gusbrs Jun 02 '22 at 13:50
  • @gusbrs Ok. I had an old file jobname.bib in my directory, so I assumed the package filecontents had created it from {\jobname.bib}. But maybe I just once forgot to add the slash. – Sverre Jun 02 '22 at 13:56

1 Answers1

5

The old filecontents environment existing in the kernel has been improved some time ago, such that the filecontents package currently passes control to the kernel. However, the kernel's filecontents environment is a little different from the one previously offered by the package in that it does not overwrite the file by default. If you want to overwrite the file, you must pass the optional argument overwrite or force. And you need no longer load the filecontents package (probably "should not", anyway not doing so gets rid of the warning).

\documentclass{article}

\usepackage{biblatex}

\begin{filecontents}[overwrite]{\jobname.bib} @book{smith1983, AUTHOR = "Harry Smith", TITLE = "My second book", YEAR = "1983"} \end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}

\nocite{smith1983}

\printbibliography

\end{document}

gusbrs
  • 13,740