I would like to use the filecontents environment in my document. I get a warning
LaTeX Warning: File `test.txt' already exists on the system.
Not generating it from this source.
If I run multiple passes of pdfLaTeX on the following
\documentclass{article}
\begin{filecontents}{\jobname.txt}
Hello World
\end{filecontents}
\begin{document}
\input{\jobname.txt}
\end{document}
The warning is obvious, the first pass creates the file, so the subsequent passes cause the warning. I thought I would be able to get rid of the warning with IfFileExists. The problem is that
\documentclass{article}
\IfFileExists{\jobname.txt}{}{
\begin{filecontents}{\jobname.txt}
Hello World
\end{filecontents}
}
\begin{document}
\input{\jobname.txt}
\end{document}
Gives me an error
! LaTeX Error: Missing \begin{document}.
on the first pass and subsequent passes. What am I doing wrong?
\IfFileExistdirectly; LaTeX enters a special state when doingfilecontentsand this makes it unhappy if the environment is in that position. – egreg Feb 13 '12 at 22:06