\choice{Pizza}
\choice{Ice Cream}
\choice{Sushi}
And then later be able to include something like:
Your choices are: \choices
And the output would be:
Your choices are: Pizza, Ice Cream, Sushi
Suggestions or pointers to help? Is there a standard idiom for this
sort of thing?
Jay
> \choice{Pizza}
> \choice{Ice Cream}
> \choice{Sushi}
>
> And then later be able to include something like:
>
> Your choices are: \choices
\gdef\choices{}
\newcommand\choice[1]{\relax
\ifx\choices\@empty\else
\g@addto@macro\choices{, }% add separators, conditionally
\fi
\g@addtomacro\choices{#1}}
Donald Arseneau as...@triumf.ca
It may not be obvious to some that the above code from Donal Arseneau
needs to be surrounded by \makeatletter and \makeatother to work inside
ordinary LaTeX documents. Also, there is an "@" symbol missing in the
second instance of "\g@addto@macro".
A modification of the macro "\choice" might be helpful. Here is the
modified and corrected source code with the addition of macro
"\finalchoice":
\makeatletter
\gdef\choices{}
\newcommand\choice[1]{\relax
\ifx\choices\@empty\else
\g@addto@macro\choices{, }% add separators, conditionally
\fi
\g@addto@macro\choices{#1}}
\newcommand\finalchoice[1]{\relax
\ifx\choices\@empty\else
\g@addto@macro\choices{, and }% conditionally add a separator and the
word "and"
\fi
\g@addto@macro\choices{#1}
}
\makeatother
The usage is like this:
\choice{dogs}
\choice{cats}
\choice{pigs}
\finalchoice{cows}
Here are your choices: \choices.
and the result is:
Here are your choices: dogs, cats, pigs, and cows.
Charles B. Cameron
[helpful stuff]
Thanks to both of you. The code was going in a class file anyway, so
the the @ business was not a problem, and witha little trial and error
I found the typo in \g@addto@macro.
Quick followup: Can anybody point me to an online source that
documents (la)tex programming at this level? I've googled and I've
googled, and can't find anything that offers much on latex programming
beyond newcommand.
Thanks again,
Jay
A corporate body for LaTeX documentation doesn't exist. No single
book, source, or archive can offer what you want.