[texhax] How to structure conditionals?
Chris Bergstresser
chris at subtlety.com
Mon Oct 24 06:49:00 CEST 2005
Karl Berry wrote:
> I'm not sure from your description how you intend \question to be
> called. Could you give an example?
Sure. Here's what I've ended up with so far:
% Define the question format
\newcommand{\question}[3]{
\samepage{}
\setcounter{questionconclude}{\substring{%
%
12112012221 % This is the definition of the
% question conclusions to use
%
}{\thequestionnum}{\thequestionnum}}
\thequestionnum) #1
\ifthenelse{\equal{\thequestionconclude}{1}}{#2}{
\ifthenelse{\equal{\thequestionconclude}{2}}{#3}{#2 \\ \ldots #3}}
\addtocounter{questionnum}{1}
}
\newcounter{questionnum}
\addtocounter{questionnum}{1}
\newcounter{questionconclude}
% Define the substring command
\def\substring#1#2#3{\expandafter\subm\romannumeral#3000x.{}%
#1\relax\relax{#2}}
\def\subm#1#2.#3#4\relax#5\relax{\csname
sub#1\endcsname#2.#4\relax#5#3\relax}
\def\subx#1.#2\relax#3\relax#4{\expandafter\submb\romannumeral#4000x.{}%
{}#3\relax}
\def\submb#1#2.#3{\csname sub#1b\endcsname#2.}
\def\subxb#1.#2\relax{#2}
Then the questions are like:
\question{
I like to eat
}
{chocolate.}
{ice cream.}
\question{
I hate
}
{rainy days.}
{Mondays.}
> I don't know how to use LaTeX conditionals, but the primitives \if and
> \ifx can check these things, or maybe \ifcase would be better. For
> example, you gave this example:
\ifcase is probably a better way of doing the above than I currently
am. Although I'd really like to define the question conclusions above
the question definition (I can't seem to find documentation for \def)
and I'd love to find a more general solution than the one I currently have.
-- Chris
More information about the texhax
mailing list