I have some LaTeX3 code and I want to add a new feature. This will involve choosing between various actions at a particular point. There are two choices to be made, and these choices are independent. The times when I read in the choice and the time when the choice is acted upon are distinct, so I need to store the choice for a bit before reading it back. As there is one choice for each term in a list, I need to store the choices in a similar list. I can think of a variety of ways of doing this and am wondering if there is a current proper way (couldn't find it in texdoc interface3) or, if not, a particular way that is better than the others.
Here are some ideas:
- This is how I would do it in a language like lua: store an integer or string in the range 0-3 and test the bits. This is, though, a bit messy with integers (
if i%2 == 0 thenis simple enough but the second bit is more likeif (i/2)%2 < 1 then) and easier with stringsif s:sub(1,1) == 0 then). - Define two new booleans and store the requisite "setting" macros. So in a token list, I store the tokens
\bool_set_true:N \l_bool_a \bool_set_false:N \l_bool_band then execute it before doing\bool_if:NTFto figure out the actions to take.
Here's what I might do in a LaTeX2 scenario in a one-shot version:
\documentclass{article}
\newif\ifchoicea
\newif\ifchoiceb
\def\saveifs{%
\edef\restoreifs{\expandafter\noexpand\csname choicea\ifchoicea
true\else false\fi\endcsname\expandafter\noexpand\csname
choiceb\ifchoiceb true\else false\fi\endcsname}
}
\def\stateofifs{%
Choice A is \ifchoicea true\else false\fi,
choice B is \ifchoiceb true\else false\fi.
}
\begin{document}
\stateofifs
\choiceatrue
\saveifs
\stateofifs
\emph{You wait.
Time passes}
\choicebtrue
\choiceafalse
\stateofifs
\restoreifs
\stateofifs
\end{document}
This produces:
Choice A is false, choice B is false.
Choice A is true, choice B is false.
You wait. Time passes
Choice A is false, choice B is true.
Choice A is true, choice B is false.
In my real use case, I'll store the "states" in an array. So in pseudo-code it might be something like:
while (getting_data) do
process_data
convert_choice_to_storable_form
push(choice_array,storeable_form)
end
do
something_complicated
end
while (rendering_data) do
pop(choice_array,storeable_form)
convert_storable_form_to_choices
foreach choice do
if choice then
do_something_stupid
else
do_something_clever
fi
end
end

blank=true(or some alias to that). I now have it that that constructs an l3key (alsoblank=true, the second layer is needed to allow for aliases). All of these keys are read before the processing starts so they need to be stored in an array. After the heavy work is done, they need to be read back to determine the choices to be made. There's no nesting involved: the processing is a closed box and can't be interrupted. – Andrew Stacey Sep 28 '12 at 8:50\keys_set:nVwhen needed? For aliases, that's what.meta:nis intended for. – Joseph Wright♦ Sep 28 '12 at 8:56