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'd like to use conditional statements in my preamble file and then define the value of the Boolean variable afterwards. The reason is that I import the preamble.tex first thing in my main file where I then want to specify switches as appropriate. I've tried this with the plain tex \newif and with the etoolbox packages, yet both seem to require the value of the Boolean variable before the definition of the conditional. This appears to mean that I would have to change my preamble.tex, defeating the purpose of making it a separate file.

Is there an easy way of achieving this, short of splitting the preamble file in two parts?

Thanks, Michael

share|improve this question
You can use \iffoo in macros defined in your preamble that are executed later but clearly if you put them at the top level so they are evaluated when the file is input, they must be defined at that point. That is not a restriction of plain tex or etoolbox, just a fact of life. – David Carlisle Apr 17 '13 at 10:20
do you mean, you want to have \foofalse in your config file, and then \input{config} followed by \newif\iffoo in your document? this is such an odd idea, i must surely be misunderstanding... – wasteofspace Apr 17 '13 at 10:27
Welcome to TeX.sx! – Peter Jansson Apr 17 '13 at 10:31
@DavidCarlisle Is there maybe a way of overriding default values? Similar to package options set after their definition? – Michael Apr 17 '13 at 10:32
It mostly depends on what your "conditional definitions" look like. Can you add a couple of examples? – egreg Apr 17 '13 at 10:35
up vote 5 down vote accepted

The approach you're following is not correct. The best thing is to change preamble.tex into preamble.sty and use options.

File preamble.sty


% The following defines \ifpreamble@foo (\if<packagename>@<optionname>)
\DeclareBoolOption[true]{foo} % specifying `foo` is the same as `foo=true`

\ExecuteOptions{foo=false} % foo is false by default



\fancyhead[R]{Michael's report}


File test.tex (foo enabled)

\usepackage[foo]{preamble} % or \usepackage[foo=true]{preamble}

File test.tex (foo disabled)

\usepackage{preamble} % or \usepackage[foo=false]{preamble}
share|improve this answer
This exactly what I was looking for. Thanks!! – Michael Apr 17 '13 at 11:09

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.