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

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

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