GeneralRenew Command inside '\ifthenelse'

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
hkarl
Posts: 3
Joined: Mon Jan 09, 2012 7:28 pm

Renew Command inside '\ifthenelse'

Post by hkarl »

Hi,

I'd like to do a \renewcommand inside an \ifthenelse. There is some discussion on various boards how this relates to scopes, \global\let etc. - but that did not help me since I want to renew a macro with a parameter. I failed to get this done with \global\let, \xdef, ...

Ideally, I'd like to write:

Code: Select all

\ifthenelse{\boolean{bla}}{
  \renewcommand{\fxnote}{}
}{}
I know this doesn't work on account of scoping, but I'm at a loss for alternative ideas (background: conditional use of commands from the fixme package).

Any help much appreciate.


Thanks & best,
Holger
Last edited by hkarl on Fri Feb 03, 2012 2:37 pm, edited 2 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
marco_d
Posts: 57
Joined: Tue Jan 20, 2009 7:49 pm

Re: Renew Command inside '\ifthenelse'

Post by marco_d »

Hi,

please provide a full minimal example.

regards
Marco
i am German. I can not use difficult words. :-)
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Renew Command inside '\ifthenelse'

Post by cgnieder »

marco_d is right: without a MWE it is very difficult to help. On first sight I don't really see the problem:

Code: Select all

\documentclass{article}
\usepackage{ifthen}

\begin{document}

\newboolean{mybool}
\newcommand*\test[1]{old: #1!}
\test{bla}

\ifthenelse{\boolean{mybool}}{true: \renewcommand*\test[1]{new: #1!}}{false: }
\test{bla}

{
\setboolean{mybool}{true}
\ifthenelse{\boolean{mybool}}{true: \renewcommand*\test[1]{new: #1!}}{false: }
\test{bla}
}

\test{bla}
\end{document}
site moderator & package author
marco_d
Posts: 57
Joined: Tue Jan 20, 2009 7:49 pm

Renew Command inside '\ifthenelse'

Post by marco_d »

Hi,

nice example. At this point I want to recommend the etoolbox package. It is really a nice package with a lot of capabilities.


Regards
Marco
i am German. I can not use difficult words. :-)
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Renew Command inside '\ifthenelse'

Post by cgnieder »

I actually thought about an example using etoolbox and nearly added it but didn't go along since the question was about ifthen.
site moderator & package author
hkarl
Posts: 3
Joined: Mon Jan 09, 2012 7:28 pm

Re: Renew Command inside '\ifthenelse'

Post by hkarl »

Hello,

I'm impressed - fast and competent :-).

The example by cgnieder put me on the right track (it was +/- exactly what I was trying to do) - sorry, I was just being stupid.

Thanks and best!

Holger
Post Reply