GeneralConditional Statements in Latex

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
stantestco
Posts: 8
Joined: Tue Jul 21, 2009 12:13 pm

Conditional Statements in Latex

Post by stantestco »

Hi, how would I go about including conditional statements in Latex?

if

\ifdef DRAFT \else
%%% do some PSTricks stuff in here
\fi


and then I'm able to set DRAFT=1 in some other file, ie a style file.

Thanks!!!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

lalop
Posts: 63
Joined: Fri Sep 11, 2009 11:25 pm

Conditional Statements in Latex

Post by lalop »

That's in tex. In latex, you'd use the ifthen package which provides stuff like

Code: Select all

\ifthenelse{     }
{


}
{


}
(Spacing changed to be suggestive; by default it's just \ifthenelse{}{}{} )
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Conditional Statements in Latex

Post by phi »

The etoolbox package offers a solution that is a bit cleaner (no namespace polluting) and faster to type:

Code: Select all

\usepackage{etoolbox}
\newtoggle{DRAFT}
...
\iftoggle{DRAFT}{yes}{no}
If you want to check for the draft class option, you should use the ifdraft package instead.
Post Reply