Answer Box 1:
Answer Box 2 (will generate if it should, or won’t if it shouldn’t!):
Feel free to hit the “Another” button above until you get both results!
How to generate a custom number of answer boxes on the fly via sage.
Often, when randomizing content, you can run into an issue where you could produce a variable number of answers. For example, lets say a problem randomly generates a quadratic function by picking both zeros and then expanding the expression . You can then have two answer boxes, one with answer of and one with answer . But what happens if you want to ask for distinct zeros? Do you force and risk students assuming quadratics always have distinct zeros? Or do you ask for the sum of solutions, and risk student confusion and/or finding shortcuts (like noticing that the sum would be the coefficient to the term)? If only you could somehow provide 1 answer box when there is only 1 distinct zero, and 2 answer boxes if there are 2 distinct zeros?
It turns out you can, using sage code with the LatexExpr command. Doing this can be a little tricky, since the input needs to be a string, but it allows you to put entire segments of LaTeX code into the sage environment - where the randomizing is taken place, then emit that content to the page to be processed by LaTeX. In particular, you can put the \answer\verb command into sage, and generate it (or not) depending on conditions in sage. Consider the following:
Answer Box 1:
Answer Box 2 (will generate if it should, or won’t if it shouldn’t!):
Feel free to hit the “Another” button above until you get both results!