37

Why does the following warning show up?

Package filecontents Warning: This package is obsolete. Disabling it and
(filecontents)                passing control to the filecontents environment
(filecontents)                defined by the LaTeX kernel.
\documentclass[nonatbib]{elsarticle}

\makeatletter
\let\c@author\relax
\makeatother

\usepackage[backend=biber,hyperref=true,doi=false,url=false,isbn=false, uniquename=false, uniquelist=false ]{biblatex}

\usepackage{filecontents,hyperref}
\begin{filecontents*}{\jobname.bib}
@Article{key,
    author =    {author},
    title =     {title},
}
\end{filecontents*}

\addbibresource{\jobname.bib}

\begin{document}
    Lorem ipsum~\cite{key}.
    \printbibliography
\end{document}
Diaa
  • 9,599

1 Answers1

48

The filecontents package was an extension to the filecontents environment already present in the LaTeX kernel for many years. LaTeX's version of the environment didn't allow it to be used outside of the document preamble and didn't allow overwriting files. The purpose of the filecontents package was, as stated in its documentation, to lift these two restrictions.

In the 2019-10-01 version of the LaTeX kernel, the filecontents environment was changed so that the two restrictions above do not exist anymore, so Scott Pakin, the author of the package, made it so that if filecontents is loaded in this new version of the LaTeX kernel, the loading of the package is aborted with a warning (no harm done, though).

The new version of the filecontens environment is backwards compatible with the old version: old documents which relied on the environment being incapable of overwriting will still work. The new version has an optional argument:

\begin{filecontents}[<options>]{<filename>}

The list of <options> accepts:

  • overwrite: This option allows the target <filename> to be written even if the file exists somewhere in the search tree. Without this option the file will not be written if either a) the file exists in the current folder or b) the file exists somewhere TeX can find (for instance, a file with the same name as a package). In any case, the environment will refuse to write on \jobname.tex, even if overwrite is used.
  • nosearch: This option will make the environment search for possible file conflicts only in the working directory, so it will only report an overwrite if the file being written to exists in the current folder.
  • noheader: This option suppresses the standard:

    %% LaTeX2e file `./<filename>'
    %% generated by the `filecontents' environment
    %% from source `test' on 2019/10/08.
    %%
    

    header written at the beginning of the output file. This option does the same as the starred form of the environment, filecontents*.

You can read more about the change to the filecontents environment and other changes to the LaTeX kernel in the 2019-10-01 update in ltnews30.

cfr
  • 198,882
  • 4
    But loading filecontents isn't backwards compatible because it won't allow overwriting? – cfr Oct 09 '19 at 02:02
  • 4
    @cfr Hm... Yes, good point. When you load the filecontents package in the new kernel, then the behaviour isn't compatible. I'd say Scott should've just incorporated the optional argument instead of making the package a no-op... – Phelype Oleinik Oct 09 '19 at 02:10
  • Thanks for the comprehensive reply. Off-topic question: is it possible to reproduce my MWE while storing/calling the bib file in a macro without creating a physical file on my PC? – Diaa Oct 09 '19 at 03:43
  • @Diaa You're welcome :-) No, I'm afraid it's not possible. The file cannot be stored in a macro because BibTeX will have to read it from outside the LaTeX run. You could create the file on-the-fly and then run BibTeX from within LaTeX, but then you wouldn't be able to delete the temporary file (unless you're using LuaTeX). – Phelype Oleinik Oct 09 '19 at 09:58
  • @PhelypeOleinik I already use lualatex, so would you recommend me to ask a question about this? Or was this question asked before? – Diaa Oct 09 '19 at 11:19
  • @Diaa I don't remember seeing it asked before, so a question would be nice (I also don't know much of LuaTeX, so... :-) – Phelype Oleinik Oct 09 '19 at 13:07
  • It took me an hour or so to figure out that the default overwriting behavior silently disappeared. – Simon Streicher Nov 12 '20 at 09:41
  • Same issue in Tex Live 2021, pdflatex. What is an alternative package forfilecontents? – sepideha Oct 11 '21 at 14:18
  • @sepideha There is no need for an alternative package. The filecontents functionality is now provided by the LaTeX kernel. – Phelype Oleinik Oct 11 '21 at 14:25