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.
  • 1
    \expandafter\newif\csname ifDTLnewboload\endcsname; but there are better ways.
    – egreg
    Feb 3, 2013 at 22:31

1 Answer 1


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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .