EDIT: Additional and specific information.
There is some useful background info that should hopefully make clear exactly what I am doing, as well as the setting this is happening in which is relevant. I'll include the problem-specific info after the ----- line.
This is for an open source project for education materials called Ximera. I am editing the code for use at a different university, and pushing those changes as they are functional up to the original project. You can find all the edited code for the cls file here (any and all incidental code is also in that github repo).
The project uses a static compile order which gives me somewhat limited options in terms of more creative solutions (for example, I would use sage for some of the desired content, but the compiler is static and won't compile the sage). The compiler isn't customized for the tex code, although it does do some magic with mathjax and some other parts that I honestly am not sure how it works.
A lot of this code, being an open source project, is somewhat cobbled together. I've been in the process of streamlining, cleaning, and commenting, as much of the code relevant to this part of the project as I can, so it should be considerably more readable than one may expect however.
Now, my actual problem is in implementing the shuffle environment features in conjunction with the "python" code environment. You can search down to the shuffle environment code in the above link (around line 860) to get the full code for shuffle which is (relatively) self contained and you can find the python/code environment (around line 750).
Immediately after the "shuffle" environment itself is all the code for the problem environment types (there are several, but the only difference is the displayed name, which should be clear from the implementation code).
My thought was to use the Environ command to collect the contents of any of the problem contents, assign it to a command that is created based on the shuffle and then problem number. Then when the shuffle environment closes, we iterate over the questions to display them in a random order. Random numbers provided by the pgfplots package, and a custom command I wrote to generate and permute a vector of numbers, saved in commands and counters.
As the code is written in the link, shuffle works great with the various problem environments. However, apparently environ package doesn't play well with verbatim environments. And since the code/python environments are verbatim environments, if we include one of these in a problem, everything blows up. So, here is a full working/nonworking example using the project code from the link above.
%\documentclass[handout]{ximera}
\documentclass[]{ximera}
\begin{document}
\begin{shuffle}[5]
\begin{exploration}% This is a basic one example that works.
Compute the following derivative:
%\expandafter\input{\file@loc Derivatives/2311-Compute-Derivative-0001.HELP.tex}
\[
\dfrac{d}{dx}\left({x^{2} - 8 \, x + 16}\right)=\answer{2 \, x - 8}
\]
\end{exploration}
\begin{problem}% This example fails due to python
This is the second problem! The answer is $\answer{6}$
\begin{hint}
test
\end{hint}
%\begin{python}% python throws a fancyvrb error
%Test
%\end{python}
\end{problem}
\begin{question}% Display mode works as an environment
This is the third problem! I need to include some other code, so here;
\[
3x + 1 = 5
\]
What is $x$? $\answer{\frac{4}{3}}$
\end{question}
\begin{exercise}
This is the fourth problem!
\begin{theorem}% Theorem environment works
The Intermediate Value Theorem is never done right by students. What is the point of this theorem?
\end{theorem}
$\answer{Nothing}$
\begin{exploration}% This doesn't appear, probably because of the approach
This just doesn't appear
\end{exploration}
\end{exercise}
\begin{problem}% This example fails.
This is the fifth problem! Lets try some nested content
%Verbatim env throw errors
%\begin{verbatim}
%Here is a hint!
%\end{verbatim}
\end{problem}
\end{shuffle}
\end{document}
The above has examples of the things that work and don't work. The verbatim and python environments straight up fail (I assume for the same reason, since python is a verbatim env created by fancyvrb). The environ package is useful for a lot of other things, so if anything I'd like to fix the verbatim side of the problem if that's possible.
As a side note, I also can't do nesting problems yet. I'm pretty sure that's just because of how shuffle is functioning and that's not too high on my list right now. It would be nice to get nesting to work, but not necessary.
scontents
, but see my other answer for a comparison between different options.