LaTeX forum ⇒ General\setboolean in \if statement Topic is solved

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

\setboolean in \if statement

Postby ziggo1879 » Sun Feb 03, 2013 11:53 pm

Hey Guys,

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

  1. \documentclass[a4paper,11pt]{article}
  2.  
  3. \usepackage{ifthen}
  4.  
  5. %booleandeclaration
  6. \newboolean{istest}
  7. \setboolean{istest}{false}
  8.  
  9. %Set boolean in if
  10. \newcommand{\activate}[1]{
  11. \ifnum#1>0{\setboolean{istest}{true}}\fi }
  12.  
  13. %test boolean of true or false
  14. \newcommand{\test}{\ifthenelse{\boolean{istest}}{TRUE}{FALSE}}%
  15.  
  16. \activate{17}
  17. \begin{document}
  18. \test
  19. \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.

Tags:

User avatar
sommerfee
Posts: 500
Joined: Mon Apr 09, 2007 4:20 pm

Postby sommerfee » Mon Feb 04, 2013 10:15 am

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
  1. \newcommand{\activate}[1]{%
  2. \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.
Reason: added inline code markup

ziggo1879
Posts: 2
Joined: Sun Feb 03, 2013 11:29 pm

Postby ziggo1879 » Mon Feb 04, 2013 7:19 pm

and it should work as expected.

Now it works fine :-).


Return to “General”

Who is online

Users browsing this forum: No registered users and 8 guests