I am trying to grasp the ins and out of LaTeX3. I want to do the following:
I have defined a environment randomizechoices
with NewDoucmentEnvironment
that grabs the contents. This contents is then parsed. When parsing, I want to split a token list on a token (to a sequence), then randomize the sequence and then build back the token list. This token list is then typeset. Now randomizing a token list is not directly available, but randomizing a sequence is. So I need to convert the token list to a (split) sequence, randomize it and build back the token list (or any way to do it). A MWE is shown below:
\documentclass{exam}
\usepackage{xparse}
\ExplSyntaxOn
% for now
\NewDocumentCommand{\inaccessible}{}{X}
\NewDocumentEnvironment{randomizechoices}{ +!b }
{
\tl_set:Nn \l_my_tl {#1}
\tl_replace_all:Nnn \l_my_tl {\CorrectChoice} {\choice \inaccessible}
\tl_replace_all:Nnn \l_my_tl {\correctchoice} {\choice \inaccessible}
% shuffle on \choice in token list
% - or -
% Convert to sequence on \choice, shuffle, rebuild
% - or -
% Convert to string, split on \choice to sequence, shuffle, rebuild
%
\begin{choices}
\tl_use:N \l_my_tl
\end{choices}
}
{}
\ExplSyntaxOff
\begin{document}
\begin{questions}
\question
Blah
\begin{randomizechoices}
\choice Hello
\choice World!
\CorrectChoice and
\choice everyone!
\end{randomizechoices}
\question
Blah
\begin{randomizechoices}
\choice Hello
\choice World!
\correctchoice and
\choice everyone!
\end{randomizechoices}
\end{questions}
\end{document}