38

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}
1
  • 5
    Because in a recent update of the LaTeX kernel the functionalities of the filecontents package (and some more) were integrated to the kernel. See ltnews30. Commented Oct 8, 2019 at 23:06

1 Answer 1

49

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.

9
  • 4
    But loading filecontents isn't backwards compatible because it won't allow overwriting?
    – cfr
    Commented Oct 9, 2019 at 2: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... Commented Oct 9, 2019 at 2: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
    Commented Oct 9, 2019 at 3: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). Commented Oct 9, 2019 at 9:58
  • @PhelypeOleinik I already use lualatex, so would you recommend me to ask a question about this? Or was this question asked before?
    – Diaa
    Commented Oct 9, 2019 at 11:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .