# [texhax] How to structure conditionals?

Karl Berry karl at freefriends.org
Tue Oct 25 01:38:35 CEST 2005

    Here's what I've ended up with so far:

Yikes.

(I can't seem to find documentation for \def)

It's a primitive, documented in the TeXbook.  (Also TeX by Topic, TeX
for the Impatient (both of which are available formatted online), and
pretty much any other non-LaTeX book. :)

and I'd love to find a more general solution than the one I currently have.

I'm still a little foggy on the details.  But I'll tell you the approach
that comes to mind anyway: it seems \question is really \definequestion,
i.e., it lists the first part and then possible second parts for each
question.  Then something else could decide which second part to use
(which is one right now with that cryptic string of numbers, right?).

So I think I would have \definequestion just define macros, more or less
like this:
\def\definequestion#1#2#3{%
\def\questionXfirst{#1}%
\def\questionXsecondi{#2}%
\def\questionXsecondii{#2}%
}
(where X is a counter that is autoincremented each question, so you
really have to use \expandafter\def\csname, etc.)

Then have another macro, say \doquestion, which typesets the desired
parts, given a question number and which second part to use:
\def\doquestion#1#2{%
\csname question#1first\endcsname
\csname question#1second#2\endcsname
}

\doquestion 1 i
\doquestion 1 ii

(Of course you could use \romannumeral as you are doing so both could be
integers, or whatever.  Lots of details.)

Probably I've totally misunderstood, but FWIW ...

Best,
Karl