6

I wonder whether there is something like the filecontents environment, but without writing the actual data to the filesystem.

With the filecontents environment, I can write a texfile like this:

\documentclass{article}
\begin{filecontents}{myfile.tex}
Hello world!
\end{filecontents}
\begin{document}
\input{myfile.tex}
\end{document}

This compiles nicely, but creates the file myfile.tex in the working directory. I wonder whether there is an alternative way to get the same compilation result, but without creating the file myfile.tex in the file system?

Alternatively, is there a command that I can put after the \end{document} to have myfile.tex removed?

silvado
  • 824

1 Answers1

8

I think luatex in principle allows you to use lua buffers in exactly the way you describe, but I don't know the details. If you do not have any verbatim material in the file you are writing out you can of course just use a macro

\documentclass{article}
\newcommand\mystuff{
Hello world!
}
\begin{document}
\mystuff
\end{document}

To remove a file at the end, if you execute latex with -enable-shell-escape you could use

\AtEndDocument{\write18{rm myfile.tex}}

or del or whatever command deletes files on your system, although it is probably just as easy to arrange the script or editor that is calling latex to simply clean up afterwards rather than rely on shell escape with latex.

David Carlisle
  • 757,742