Python/Sage TeX

Within the project, we have been able to experiment with various software tools for Mathematics.

Python TeX and Sage TeX offer ways to mix LaTeX and code in Python or Sage. This offers various ways of generating parameterized exercises, ready to be printed.

We have also developped some Python scripts such that the LaTeX sources can be translated to the syntax of ANS,or of Oncourse. This makes it possible to use the exercises for written exams, but also for online exams in ANS or OnCourse. Tools for translating the exercises to Grasple are being considered.

Below you find the source of a simple parametrized exercise on adding fractions.

\question
\begin{pycode}

a=sp.randprime(2, 12);
b=sp.randprime(2, 12);
c=sp.randprime(b, 12);
d=ra.randint(4, 9);
e=ra.randint(4, 9);
f=ra.randint(e+1, 10);



g=(sp.simplify(sp.Rational(a,d)-sp.Rational(b,e)+sp.Rational(c,f)));
g1=sp.Rational((a+b+c),(d-e+f));
g2=sp.Rational((a-b+c),(d+e+f));
g3=sp.Rational((a+b+c),(d+e+f));

correct=sp.latex(g);
wrong1=sp.latex(g1);
wrong2=sp.latex(g2);
wrong3=sp.latex(g3);
\end{pycode}


The expression $\frac{\py{a}}{\py{d}}-\frac{\py{b}}{\py{e}}+\frac{\py{c}}{\py{f}}$ equals

\begin{multicols}{2}
\begin{randomizechoices}
\choice $\py{wrong1}$
\choice $\py{wrong2}$
\choice $\py{wrong3}$
\CorrectChoice $\py{correct}$
\end{randomizechoices}
\end{multicols}