12

The old environment (before 10/2019)

 \usepackage{filecontents}
 \begin{filecontents}{tabelle.tex}
  ... some text ...
 \end{filecontents}`

will overwrite an existing file tabelle.tex.

After my update yesterday in debian sid, it does not work any more.

I removed the \usepackage{filecontents} because the functionality should now be inside the LaTeX kernel.

But filecontents will not overwrite my file (with respective message in log):

LaTeX Warning: File 'tabelle.tex' already exists on the system.
               Not generating it from this source.

Trying to force overwrite with \begin{filecontents}[overwrite]{tabelle.tex} leads to error:

! LaTeX Error: Trying to overwrite 'kivitendo-print7y2OSd.tex'.

So it looks like it tries to overwrite the encompassing file.

Is this a bug or am I missing a point?

Edited 09.11.2019:

Minimal example:

\documentclass{article}
\usepackage{etex}
\begin{filecontents}[overwrite]{addfile.tex}
    \centering{Hello World!}
\end{filecontents}
\begin{document}
    Just a test.
\end{document}

Apparantly, the \usepackage{etex} causes the error. The latex code is used by the web application kivitendo. Within my short test, I see no drawback to eliminate the package 'etex'.
After that, for me it's working.

Volker
  • 121
  • 1
    Welcome to TeX.SX! Could you please provide a minimal example that reproduces the problem? – Phelype Oleinik Nov 01 '19 at 14:30
  • Are you sure you're using the new kernel? We've seen a lot of people where the packages were updated but not the kernel. The kernel version is listed at the top of the log – daleif Nov 01 '19 at 14:41
  • 3
    @daleif The message Trying to overwrite ... was introduced in the new kernel when trying to write on \jobname.tex, so it should be the new version. OP probably has some code writing on \jobname.tex, for some reason. Impossible to tell without an example... – Phelype Oleinik Nov 01 '19 at 14:48
  • @PhelypeOleinik I like that the message seems to occur only in case \jobname.tex exists. (This is not necessarily the case when calling latex with the -jobname=...-option. ;-) ) – Ulrich Diez Nov 02 '19 at 13:40
  • @UlrichDiez Yes, the overwrite-check code is only executed if the target file exists, so if \jobname.tex does not exist. it should be safe to write on it. That's one of the problems we discussed when writing this implementation. There's no reliable way to test “am I trying to write on the current source?”, so the approach we agreed on was to test for \jobname.tex, which will be correct most of the time. Everywhere else, user's discretion is advised. – Phelype Oleinik Nov 02 '19 at 14:19
  • In a simple example I tried \begin{filecontents}[overwrite]{notatabelle.tex} resulted in LaTeX Warning: Writing or overwriting file `./notatabelle.tex'. and a correctly overwritten file notatabelle.tex. Can you show a full example document (and explain how you compile that document) that reproduces this weird behaviour? – moewe Nov 02 '19 at 14:21
  • Ulrike opened an issue at the etex bugtracker: https://github.com/davidcarlisle/dpctex/issues/23, there is also some discussion about this in chat starting from https://chat.stackexchange.com/transcript/message/52492694#52492694 – moewe Nov 09 '19 at 17:33

2 Answers2

10

The main difference is the old definition of \ch@ck that is re-instated by etex.sty

The error could be avoided by

\documentclass{article}
\makeatletter
\let\zzz\ch@ck
\usepackage{etex}
\let\ch@ck\zzz
\makeatother

\begin{filecontents}[overwrite]{addfile.tex}
    \centering{Hello World!}
\end{filecontents}
\begin{document}
    Just a test.
\end{document}

but a much better fix would be to simply not use etex.sty it shouldn't be used in any documents written after 2015, and no documents written before 2015 can be using \begin{filecontents}[overwrite]

Ulrike has opened an issue on etex.sty bug tracker, we could perhaps adjust the definition of \ch@ck in the package, as above, but any change may affect compatibility with other packages assuming the original definitions, and compatibility with such packages is the only reason for etex.sty these days, so I'm not sure.

David Carlisle
  • 757,742
2

As filecontents of LaTeX 2ε 2019‑10‑01 Patch level 1 uses \ifeof for checking the existence of the file in question, you can outmanoeuvre the file-existence-check by temporarily refefining \ifeof to deliver \iftrue after removing the token which denotes the \ifeof-read-handle:

\NeedsTeXFormat{LaTeX2e}[2019-10-01 Patch level 1]
\documentclass{article}

\begingroup
\global\let\savedifeof=\ifeof
\def\ifeof#1{\global\let\ifeof=\savedifeof\iftrue}%
\begin{filecontents}{tabelle.tex}
... some text ...
\end{filecontents}
\endgroup

\begin{document}
Bla
\end{document}

I showed this just for the sake of having fun while playing around with the latest novelties.

I cannot recommend this for serious work.

Instead I strongly recommend tracking the cause of the erroneous behavior.

For doing this, a compilable complete minimal example is needed by means of which the erroneous behavior can be reproduced.
\listfiles and the look of the .log-file might be of interest, too, so one can find out what package-versions etc are in use.

Ulrich Diez
  • 28,770
  • Formatting of comments (code, linebreaks) as mentioned in help does not work, so I will edit my original quesiton. – Volker Nov 09 '19 at 14:37