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.

The MWE below attemps to define a \newif within a \ifdefined. This works fine, except when the file is loaded the second time.

As it is below generates the following error message:

Incomplete \ifdefined; all text was ignored after line 1.

However if you comment out the \newif works as desired.


How do I declare the \newif within the \ifdefined?



        \newcommand{\SomeCommand}{some command}%

Lorem ipsum
\input{MyHeader.tex} \SomeCommand.

\input{MyHeader.tex} \SomeCommand.
share|improve this question
\expandafter\newif\csname ifDTLnewboload\endcsname; but there are better ways. –  egreg Feb 3 '13 at 22:31

1 Answer 1

up vote 9 down vote accepted

In order not to load a file twice, another method is preferable:

%%% MyHeader.tex

\newcommand{\SomeCommand}{some command}

If the file has already been loaded, the control sequence would be defined. So the conditional expands \endinput that stops reading the file. The \expandafter is just to finish the conditional. A different format would be

%%% MyHeader.tex

\newcommand{\SomeCommand}{some command}

because TeX always ends the line before \endinput does its work.

To answer the original question,

\expandafter\newif\csname ifDTLnewdbonload\endcsname

would work, because if TeX skips the \else branch, it will not "see" the already defined conditional.

share|improve this answer

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.