ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 07 Jun 2015 00:01:12 +0200Student worksheet to embed in website using sagehttps://ask.sagemath.org/question/27034/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!Sat, 06 Jun 2015 01:09:11 +0200https://ask.sagemath.org/question/27034/student-worksheet-to-embed-in-website-using-sage/Answer by tmonteil for <p>As a teacher, I find myself very excited about the below</p>
<pre><code>\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}
</code></pre>
<p>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).</p>
<p>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.</p>
<p>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?</p>
<p>I have a good amount of time this summer to learn new things so any kind of solution is welcome!</p>
https://ask.sagemath.org/question/27034/student-worksheet-to-embed-in-website-using-sage/?answer=27037#post-id-27037It 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.Sat, 06 Jun 2015 10:33:31 +0200https://ask.sagemath.org/question/27034/student-worksheet-to-embed-in-website-using-sage/?answer=27037#post-id-27037Comment by Shai for <p>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.</p>
https://ask.sagemath.org/question/27034/student-worksheet-to-embed-in-website-using-sage/?comment=27040#post-id-27040When 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.Sat, 06 Jun 2015 19:07:34 +0200https://ask.sagemath.org/question/27034/student-worksheet-to-embed-in-website-using-sage/?comment=27040#post-id-27040Answer by dazedANDconfused for <p>As a teacher, I find myself very excited about the below</p>
<pre><code>\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}
</code></pre>
<p>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).</p>
<p>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.</p>
<p>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?</p>
<p>I have a good amount of time this summer to learn new things so any kind of solution is welcome!</p>
https://ask.sagemath.org/question/27034/student-worksheet-to-embed-in-website-using-sage/?answer=27035#post-id-27035Actually, I think you do want the Sage Cell Server. For example, copy this simple example into a [Sage Cell Server](https://sagecell.sagemath.org/):
@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.Sat, 06 Jun 2015 01:53:15 +0200https://ask.sagemath.org/question/27034/student-worksheet-to-embed-in-website-using-sage/?answer=27035#post-id-27035Comment by Shai for <p>Actually, I think you do want the Sage Cell Server. For example, copy this simple example into a <a href="https://sagecell.sagemath.org/">Sage Cell Server</a>:</p>
<pre><code>@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)))
</code></pre>
<p>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.</p>
https://ask.sagemath.org/question/27034/student-worksheet-to-embed-in-website-using-sage/?comment=27041#post-id-27041Thank 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.]Sat, 06 Jun 2015 19:17:06 +0200https://ask.sagemath.org/question/27034/student-worksheet-to-embed-in-website-using-sage/?comment=27041#post-id-27041Comment by dazedANDconfused for <p>Actually, I think you do want the Sage Cell Server. For example, copy this simple example into a <a href="https://sagecell.sagemath.org/">Sage Cell Server</a>:</p>
<pre><code>@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)))
</code></pre>
<p>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.</p>
https://ask.sagemath.org/question/27034/student-worksheet-to-embed-in-website-using-sage/?comment=27042#post-id-27042I'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](http://www.highschoolmathandchess.com/) to guide you.Sat, 06 Jun 2015 20:35:37 +0200https://ask.sagemath.org/question/27034/student-worksheet-to-embed-in-website-using-sage/?comment=27042#post-id-27042Comment by dazedANDconfused for <p>Actually, I think you do want the Sage Cell Server. For example, copy this simple example into a <a href="https://sagecell.sagemath.org/">Sage Cell Server</a>:</p>
<pre><code>@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)))
</code></pre>
<p>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.</p>
https://ask.sagemath.org/question/27034/student-worksheet-to-embed-in-website-using-sage/?comment=27045#post-id-27045That's an interesting option I'd never heard of. Will have to explore more. Thanks!Sun, 07 Jun 2015 00:01:12 +0200https://ask.sagemath.org/question/27034/student-worksheet-to-embed-in-website-using-sage/?comment=27045#post-id-27045Comment by kcrisman for <p>Actually, I think you do want the Sage Cell Server. For example, copy this simple example into a <a href="https://sagecell.sagemath.org/">Sage Cell Server</a>:</p>
<pre><code>@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)))
</code></pre>
<p>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.</p>
https://ask.sagemath.org/question/27034/student-worksheet-to-embed-in-website-using-sage/?comment=27043#post-id-27043By 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".Sat, 06 Jun 2015 20:36:15 +0200https://ask.sagemath.org/question/27034/student-worksheet-to-embed-in-website-using-sage/?comment=27043#post-id-27043