# LaTeX command or environment to selectively print one out of several given options

I'm currently wasting my time by trying to create a proof-of-concept class to show that writing our university's curricula with LaTeX instead of MS Word would have some benefits. Since these curricula are essentially legal documents, there already exists a template with some fixed wording, some options to choose from, and some space to insert material specific to that study programme (e.g. tables of mandatory courses). My idea is to prvide commands that specify comments (only to be shown in draft mode), examples to be replaced (otherwise throwing an error in final mode, so they are not overlooked), and so on. Most of these I can probably figure out by myself, but for one I don't have enough experience yet: I'd like a command or environment/list with the following properties.

• accepts a variable number of arguments or items (up to 4 mostly) with arbitrary contents (usually a sentence or paragraph, sometimes also a longtable or such)
• in draft mode prints out all arguments/items
• in final mode throws an error, unless one of the given options is selected (by an optional argument to the command/environment)

If there isn't already a package for this, I'm open to custom solutions or suggestions to achieve the same functionality with other means.

EDIT: Here is an example of such a command and an environment:

\choose[3]{Option A}{Option B}{Option C}
% in draft mode prints: Option A / Option B / Option C
% in final mode throws an error
\choose[2][3]{Option A}{Option B}{Option C}
% in either mode prints: Option B

\begin{select}
\item Paragraph A
\item Paragraph B
% ...
\item Paragraph Z
\end{select}
% in draft mode prints all paragraphs (with some separator in between)
% in final mode throws an error

\begin{select}[2]
\item Paragraph A
\item Paragraph B
% ...
\item Paragraph Z
\end{select}
% in either mode prints Paragraph B

• if statements depending on draft option perhaps? – user31729 Apr 12 '15 at 16:47
• I referred to the draft option just for some context. The actual problem is the variable-argument command / environment from which an option has to be selected which will then be printed. – pazathoth Apr 12 '15 at 16:51
• can you explain more with some example if possible. I can think in some thing like this tex.stackexchange.com/questions/237941/… – touhami Apr 12 '15 at 17:12
• @pazathoth: I am still trying to figure out, what your are after – user31729 Apr 12 '15 at 17:37
• @pazathoth: I think, it's a little bit clearer, but I would prefer another syntax – user31729 Apr 12 '15 at 20:12

For example \mychoose macro can be defined like this:

\newcount\optnum
\newif\ifdraftmode  \let\finalmodetrue=\draftmodefalse \let\finalmodefalse=\draftmodetrue

\def\mychoose[#1]{\bgroup\def\optcount{#1}\futurelet\next\mychooseA}
\def\mychooseA{\ifx\next[\def\next{\mychooseB}\else \def\next{\mychooseB[0]}\fi \next}
\def\mychooseB[#1]{%
\ifdraftmode \ifnum#1>0 \draftmodefalse \fi\fi
\ifdraftmode\else
\ifnum#1=0
\errmessage{\string\mychoose: no parameter specified in final mode}%
\def\realopt{0}%
\else \let\realopt=\optcount \def\optcount{#1}\fi
\fi
\optnum=0 \mychooseC
}
\ifdraftmode\tmp\else \ifnum\realopt=\optnum\tmp \fi\fi
\ifnum\optcount>\optnum \expandafter\mychooseC \else \egroup\fi
}

%% test:
\finalmodefalse
\mychoose[3]{Option A}{Option B}{Option C}

\finalmodetrue
\mychoose[2][3]{Option A}{Option B}{Option C}


and {select} environment can be defined like this:

\newcount\optnum
\newif\ifdraftmode  \let\finalmodetrue=\draftmodefalse \let\finalmodefalse=\draftmodetrue

\def\selectB{\futurelet\next\selectC}
\def\selectC{\ifx\next[\def\next{\selectD}\else \def\next{\selectD[0]}\fi \next}
\def\selectD[#1]{\def\realopt{#1}%
\ifdraftmode\else \ifnum#1=0
\errmessage{{select}: no parameter specified in final mode}\fi\fi
\ifnum#1=0 \else \draftmodefalse \fi
\par \optnum=0
\ifdraftmode\else \ifnum\realopt=\optnum \else \setbox0=\vbox \fi\fi
\bgroup}
\bgroup
}
\def\selectE{\par\egroup}
\newenvironment{select}\selectB\selectE

%% test:
\finalmodefalse
\begin{select}
\item Paragraph A
\item Paragraph B
\item Paragraph Z
\end{select}

\finalmodetrue
\begin{select}[2]
\item Paragraph A
\item Paragraph B
\item Paragraph Z
\end{select}


But I doubt that you have chosen the optimal strategy.