I'm trying to define a variable conditional on the setting of a counter, with an optional argument. Specifically, in the example below, the variable
gOpt
should return the second argument if the counter general is set to 1, and the first if the counter is set to 0
. If only one argument is provided, and general = 0
, the default should be used.This command works fine *if* only one argument is provided, but if two are provided,
gOpt
returns both #1
and #2
, rather than choosing depending on the value of \thegeneral
.If I use a
\def
command, (gAlt
) then everything works ok, but I can't specify a default option.Is this a bug in
\providecommand
? Is there an easy way around the problem? Thanks very much for any advise.Code: Select all
\documentclass[11pt,reqno,fleqn]{amsart}
\usepackage{ifthen}
\newcounter{general}
\setcounter{general}{1}
\providecommand{\gOpt}[2][this is the specific case]{\ifthenelse{\thegeneral=1}{#2}{#1}}
\def\gAlt#1#2{\ifthenelse{\thegeneral=1}{#2}{#1}}
\begin{document}
\gOpt{this is the general case}
\gOpt{this is the specific case}{this is the general case}
\gAlt{this is the specific case}{this is the general case}
\ifthenelse{\thegeneral=1}{this is the general case}{this is the specific case}
\end{document}