General\setboolean in \if statement

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
ziggo1879
Posts: 2
Joined: Sun Feb 03, 2013 11:29 pm

\setboolean in \if statement

Post by ziggo1879 »

Hey Guys,

I try to set a boolean in a if-statement but Latex seems to ignore my input.

Code: Select all

\documentclass[a4paper,11pt]{article}

\usepackage{ifthen}

%booleandeclaration
\newboolean{istest}
\setboolean{istest}{false}

%Set boolean in if
\newcommand{\activate}[1]{
\ifnum#1>0{\setboolean{istest}{true}}\fi }

%test boolean of true or false
\newcommand{\test}{\ifthenelse{\boolean{istest}}{TRUE}{FALSE}}%

\activate{17}
\begin{document}
\test
\end{document}
I thought the \activate{17} statement would set the boolean "istest" to true, but it dosen't, \test returns FALSE.

Any idea why the \setboolean statement not works correctly in the \ifnum statement?

Ziggo
Last edited by ziggo1879 on Mon Feb 04, 2013 7:26 pm, edited 3 times in total.

Recommended reading 2024:

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

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

sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

\setboolean in \if statement

Post by sommerfee »

ziggo1879 wrote:\newcommand{\activate}[1]{
\ifnum#1>0{\setboolean{istest}{true}}\fi }
This keeps the effect of \setboolean local to the group (opened right before \setboolean with { ), but since you close the group right after \setboolean this code has actually no effect.

So change it to

Code: Select all

\newcommand{\activate}[1]{%
  \ifnum#1>0 \setboolean{istest}{true}\fi}
and it should work as expected.
Last edited by cgnieder on Mon Feb 04, 2013 12:02 pm, edited 1 time in total.
ziggo1879
Posts: 2
Joined: Sun Feb 03, 2013 11:29 pm

\setboolean in \if statement

Post by ziggo1879 »

and it should work as expected.
Now it works fine :-).
Post Reply