I want to create different versions of an exam paper and corresponding sample solutions using sagetex. I need to assign variables for more involved computations, so I am reliant on the sagesilent environment. However, this environment seems to be a type verbatim environment and that seems to be incompatible with \foreach loops the the pgffor package provides. The latter is needed to generate the different versions of the exam.
Error messages look like this:
ERROR: Paragraph ended before \verbatim@ was complete.
Is there a way to make the two packages work together? Ideally, a solution would optionally allow the expansion of macros in the sagesilent environment, like in this answer.
An MWE example is given below (without macro expansion).
\documentclass{minimal}
\usepackage{pgffor}
\usepackage{sagetex}
\begin{document}
\foreach \x/\y in {3/4,5/6,7/8} {
The product of $\x$ and $\y$ is $\sage{\x*\y}$. % this works
% but not this: (the assignment z= cannot be done in \sage{})
\begin{sagesilent}
z=2*9
\end{sagesilent}
}
\end{document}
pgfforis a placeholder for that. I guess my main problem is that I need sagetex environments that can be stored in a macro and be evaluated (by sage) only once the macro is expanded. For this, verbatim-type environments seem to be the wrong path. – bjoseru Jan 13 '16 at 21:28