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 am using conditional tests in my .cls file which has two options "final" and "draft". I am rather familiar with conditional tests but I am just curious to know how to define the "or" in the following code.

\if@‎final OR ‎\if@draft FINAL TEST ‎‎ ‎\else NO TEST‎ ‎\fi\fi


I have tried the following code and have gotten the desired result, so I just want to know whether I CAN use something like "\or" in \newif conditional or not. In other word, does such a command (I mean \or) exist at all?

‎\newcommand{‎\mytest‎}‎{\if@‎final FINAL TEST ‎\else‎  ‎\if@draft FINAL TEST ‎‎ ‎\else ‎NO ‎TEST‎ ‎\fi\fi‎‎‎‎‎}‎‎
share|improve this question
Do you have different outputs based on whether you're final or draft, since your faux if statement doesn't show it? – Werner Dec 29 '11 at 22:24
In both cases, I want to have "FINAL TEST" on my output. – Vahid Damanafshan Dec 29 '11 at 22:31
Yes, \or exists, but is not used in the context of boolean expressions like you might be used to. Instead it is used as a choice conditioning when using \ifcase. See some examples of \or in the TeX Primitive Control Sequence Reference. – Werner Dec 29 '11 at 23:56
up vote 11 down vote accepted

The basis for your OR statement looks like this:

\if@final TRUE\else\if@draft TRUE\else FALSE\fi\fi

The following minimal example illustrates this:

\newif\if@final \newif\if@draft
\newcommand{\test}{\if@final TRUE\else\if@draft TRUE\else FALSE\fi\fi}
% final = false; draft = false
\@finalfalse \@draftfalse \test

% final = true; draft = false
\@finaltrue \@draftfalse \test

% final = false; draft = true
\@finalfalse \@drafttrue \test

% final = true; draft = true
\@finaltrue \@drafttrue \test

yielding the OR truth table:

enter image description here

Comparable output is obtained by using booleans defined via etoolbox:

\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
%\newif\if@final \newif\if@draft
\newbool{@final} \newbool{@draft}
\newcommand{\test}{\ifboolexpr{bool {@final} or bool {@draft}}{TRUE}{FALSE}}
% final = false; draft = false
\boolfalse{@final} \boolfalse{@draft} \test

% final = true; draft = false
\booltrue{@final} \boolfalse{@draft} \test

% final = false; draft = true
\boolfalse{@final} \booltrue{@draft} \test

% final = true; draft = true
\booltrue{@final} \booltrue{@draft} \test

Of course, you can change the TRUE/FALSE output to whatever you want.

As Marco remarked, etoolbox's boolean flags provide a front-end to LaTeX's \newif. As such you can either define them using \newbool or \newif. See section 3.5 Boolean Flags (p 12 onward) of the etoolbox documentation.

share|improve this answer
Since \ifboolexpr and \ifboolexpe imply processing overhead, there is generally no benefit in employing them for a single/simple test. etoolbox documentation. – Ahmed Musa Dec 30 '11 at 8:35
  • Your example doesn't implement a class so I'm assuming you're trying to implement a package.
  • If the user-defined-command doesn't rely on arguments, then it's more efficient if you define it using \edef.

In the following, I show how to implement the parsing with the pgfopts package, which makes pgfkeys-style option parsing available. I find it much easier to use in general than using other packages that provide key=value parsing. More information about pgfkeys may be found in the pgf manual.


% Define the main TeX switches

% Define the final and draft options. Both default to false.
         final/.is if=mypackage@final,                      
         draft/.is if=mypackage@draft,                      

        DRAFT and FINAL.%
        FINAL only.%

        DRAFT only.
        NOTHING, you lose.%

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.