TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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 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.