Ask Your Question
2

Student worksheet to embed in website using sage

asked 2015-06-06 01:09:11 +0100

Shai gravatar image

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!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2015-06-06 01:53:15 +0100

dazedANDconfused gravatar image

updated 2015-06-06 01:57:23 +0100

Actually, I think you do want the Sage Cell Server. For example, copy this simple example into a Sage Cell Server:

@interact
def Midpoint(ShowSolution=checkbox(default=True, label='Check to show solution')):
    x1=Integer(randint(-5,10))
    x2=Integer(randint(-5,10))
    y1=Integer(randint(-5,10))
    y2=Integer(randint(-5,10))
    html('Find the midpoint of $(%s,%s)$ and $(%s,%s)$.'% (x1,y1,x2,y2))
    if ShowSolution==True:
        html('$M=\\left(\\frac{(%s)+(%s)}{2},\\frac{(%s)+(%s)}{2}\\right)$'%(x1,x2,y1,y2))
        html('$M=\\left(\\frac{%s}{2},\\frac{%s}{2}\\right)$'%(x1+x2,y1+y2))
        if (x1+x2)/2 in ZZ or(x1+x2)/2 in ZZ:
            html('$M=\\left(%s,%s\\right)$'%(latex((x1+x2)/2),latex((y1+y2)/2)))

You can probably see the LaTeX portion is done through html. Notice also that backslashes are now double backslashes. You can press "Evaluate" for more problems or redesign the code to allow student select the number of problems.

edit flag offensive delete link more

Comments

Thank you for this -- this is certainly a solution I can implement and, in fact, I plan to do so for the next academic year whilst I learn more web design. The LaTeX --> Sage --> Latex --> PDF solution is my ultimate preference simply because I can create every worksheet as a .tex file and use some as hard copies for homework and unit assessments (so absentees can sit a numerically different test without being told the answers from other students!) and then feed others to the VLE so that students can practise to their hearts' content. This ought to bring some unity to my collection of teaching resources and allow me to pass random parameters to polylongdiv, TiKz and other, self-defined macros. [I would upvote both but I have only 11 Karma.]

Shai gravatar imageShai ( 2015-06-06 19:17:06 +0100 )edit

I've struggled with this problem a bit. Given your preference (which is actually the route I'm on) I think it's just about creating LaTeX documents using sagetex package to access Sage's math capabilities. Creating the problems takes a lot of time because of the debugging aspect and for unexpected times when Sage takes your input or output and represents it in a way you don't want. (try having Sage do the quotient rule). Depending on the problem, randomly created problems can be extremely complicated and forcing Sage to show what you want can be extremely time consuming. One use of Sage was to create random problems and then pick out the "best" ones for a quiz/test. You can find lots of examples here to guide you.

dazedANDconfused gravatar imagedazedANDconfused ( 2015-06-06 20:35:37 +0100 )edit

By the way, if you are interested in a different workflow, you may want to try MathbookXML http://mathbook.pugetsound.edu/ which could allow you to "write once, print multiple ways".

kcrisman gravatar imagekcrisman ( 2015-06-06 20:36:15 +0100 )edit

That's an interesting option I'd never heard of. Will have to explore more. Thanks!

dazedANDconfused gravatar imagedazedANDconfused ( 2015-06-07 00:01:12 +0100 )edit
2

answered 2015-06-06 10:33:31 +0100

tmonteil gravatar image

updated 2015-06-06 10:37:49 +0100

It depends on how your website is hosted. Do you have access to it, e.g. a professional homepage hosted on a server with Sage installed ? In which case a cgi script (python, php, whatever) that runs the compilation when called will be a straightforward solution.

edit flag offensive delete link more

Comments

When I began this site, I chose WordPress hosted through siteground as a way of easily creating an attractive environment for my students with social features and easy admin without too much of a learning curve on my part. I think it should be possible to use sage in conjunction with siteground, based on a few minutes research. All in all, I have managed to get a website running using mostly cut/paste, plugins and my knowledge of LaTeX/Sage/Python. I think that, if I am to get what I want the way I want it, there is no way around learning more about cgi, html and web development as a whole. Thank you for your input! Now I need to stop being lazy and learn how to actually make a website.

Shai gravatar imageShai ( 2015-06-06 19:07:34 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-06-06 01:09:11 +0100

Seen: 1,346 times

Last updated: Jun 06 '15