# Boolean switch for conditional statement after its definition?

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

-
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

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

\ProvidesPackage{preamble}
\RequirePackage{kvoptions}

% 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

\ProcessKeyvalOptions{preamble}

\RequirePackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}

\ifpreamble@foo
\fi

\endinput


## File test.tex (foo enabled)

\documentclass{article}
\usepackage[foo]{preamble} % or \usepackage[foo=true]{preamble}
\usepackage{kantlipsum}
\begin{document}
\section{A}
\kant
\end{document}


## File test.tex (foo disabled)

\documentclass{article}
\usepackage{preamble} % or \usepackage[foo=false]{preamble}
\usepackage{kantlipsum}
\begin{document}
\section{A}
\kant
\end{document}

-
This exactly what I was looking for. Thanks!! –  Michael Apr 17 '13 at 11:09