Take the 2-minute tour ×
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.

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
add comment

2 Answers

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

...
\newif\iftim@write
\DeclareOption{nowrite}{\tim@writefalse}
\DeclareOption{write}{\tim@writetrue}
...
\ExecuteOptions{...,nowrite}% or write, if you prefer
\ProcessOptions\relax
...

\iftim@write
  \def\tim@write{\immediate\write}
\else
  \let\tim@write\@gobbletwo
\fi

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
add comment

The command \nofiles switches off all file writing LaTeX

share|improve this answer
3  
It switches off the writing of files that use \protected@write. –  egreg Nov 12 '11 at 20:19
1  
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
add comment

Your Answer

 
discard

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.