TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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'm working on package that (among other things) writes an external file during compilation. I'd like to provide an option to the package to not write the external file.

I know I can set up a boolean and test for it everywhere in the package the writes take place. But it would be nice to just set the openout command at the beginning to write to /dev/null or its equivalent.

Is that possible? I need to keep this package supported on Windows, Mac, and Unix.

share|improve this question
up vote 12 down vote accepted

The writing is probably done by \immediate\write\STREAM{...}; I usually define a macro to stand for \immediate\write so its meaning can be changed at will

\ExecuteOptions{...,nowrite}% or write, if you prefer


This code is for the case where your writing operations are done or not via a package option.

If the boolean is true, \tim@write\STREAM{...} would be expanded to \immediate\write\STREAM{...}; if the boolean is false, the same tokens would become \@gobbletwo\STREAM{...}, so \STREAM and {...} will vanish.

share|improve this answer
That is an elegant solution @egreg. I love its simplicity! thanks. – Tim A Nov 12 '11 at 22:01

The command \nofiles switches off all file writing LaTeX

share|improve this answer
It switches off the writing of files that use \protected@write. – egreg Nov 12 '11 at 20:19
And also disables creation of index and glossary. – Andrey Vihrov Nov 12 '11 at 20:24
@andrey-virhov yes, this is the intended behavior – Boris Nov 12 '11 at 20:52

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.