3

I would like to define filecontents blocks before documentclass in my LaTeX document. Is there any way to suppress warning Writing or overwriting file ./filename?

My MWE is as follows:

\begin{filecontents}[overwrite]{test.txt}
test
\end{filecontents}

\documentclass{article}

\usepackage{silence}
\WarningFilter{latex}{Writing file}

\begin{document}
\input{test.txt}
\end{document}
6
  • 1
    Out of curiosity, what's the purpose of (wrongly) redefining \ifeof?
    – egreg
    May 31, 2021 at 14:25
  • This is the scheme what I found for overwriting the existing files. If you have a better construction, please share with me. :)
    – TobiR
    May 31, 2021 at 14:26
  • why do you want to suppress the warning? You will only get it once, and not if the file exists. May 31, 2021 at 14:26
  • @UlrikeFischer For each file. I have a lot of files.
    – TobiR
    May 31, 2021 at 14:27
  • 1
    If you always want to write the files, use \begin{filecontents}[overwrite]{filename}
    – egreg
    May 31, 2021 at 14:29

1 Answer 1

3

You can load silence before \documentclass.

\RequirePackage{silence}
\WarningFilter{latex}{Writing or overwriting file}

\begin{filecontents}[overwrite]{\jobname.txt}
test
\end{filecontents}

\documentclass{article}

\begin{document}

\input{\jobname.txt}

\end{document}

If you're running an older release of LaTeX where the overwrite option does not exist, add \RequirePackage{filecontents} at the very beginning. Don't do that trick involving redefining \ifeof.

On the other hand, I'd like to be informed about write operations of this kind.

(I changed the file name not to risk clobbering my files.)

1
  • Thanks egreg. Your solution works well, but now that I have removed \ifeof and added [overwrite] to filecontents, the warning has changed to Writing or overwriting file. By the way, this document version is only for submitting it to a journal in a single file. It looks nicer if there are no warnings during compilation.
    – TobiR
    May 31, 2021 at 14:42

You must log in to answer this question.

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