TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

Hello world!

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?

share|improve this question
In ConTeXt buffers do exactly what you ask for. – Marco May 30 '13 at 12:18
up vote 8 down vote accepted

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

Hello world!

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.

share|improve this answer
I would use a \long\def so that he could use multi-paragraph definitions. – Steven B. Segletes May 30 '13 at 12:36
@StevenB.Segletes or even \newcommand :-) (answer edited) – David Carlisle May 30 '13 at 12:49
@StevenB.Segletes Doesn't apply here: it's arguments that cannot be long with \def, not the replacement text itself. – Joseph Wright May 30 '13 at 12:51
Defining a new macro / command works actually well for my case, thanks for that :) Seems like I had an XY-Problem... – silvado May 30 '13 at 12:52
@JosephWright Thanks. Not sure why I thought that was the case, but I appreciate the correction. – Steven B. Segletes May 30 '13 at 12:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.