Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Student worksheet to embed in website using sage

As a teacher, I find myself very excited about the below

\documentclass{article}
\usepackage{sagetex}

\begin{document}

\begin{sagesilent}
r1 = randint(1,5)
r2 = randint(1,5)
\end{sagesilent}

\textbf{Problem} What is $\sage{r1}+\sage{r2}$?

\textbf{Answer} The answer is $\sage{r1+r2}$

\end{document}

Now, what I want more than anything is to embed the output onto my website and allow students to hit a 'recompile' button to generate a new random problem. My criteria are flexible: I want the beauty of a typesetted latex document (which probably means embedding a pdf viewer or something) and the ability to call arbitrary latex packages (which rules out MathJax, unless I can somehow call into play Sage's %latex and add_to_preamble commands).

I have tried using a sagecell, but the output from %latex-ing the whole cell doesn't display the graphic, it only displays a string of raw latex. Besides, I really would prefer to write in latex with SageTeX than to write in sage with %latex.

I'm not expecting someone to solve this problem for me, but if anyone has any idea how I could achieve this on another website (with a latex rendering server which supports SageTeX) or something then any advice would be hugely appreciated. Could the sagecloud itself serve its latex/sage/latex routine and send back a pdf or image to display?

I have a good amount of time this summer to learn new things so any kind of solution is welcome!