Ask Your Question

Implementing Sage on Website

asked 2012-02-20 07:45:33 -0600

anonymous user


updated 2012-02-20 15:42:24 -0600

Shashank gravatar image

Here is what I would like to do; please let me know what might be the best way/programs to use to do it:

*Write Python code, involving Sage commands/functions

*Have a website where user input is taken, and the code is run

*The output of the Python code is not to be displayed exactly; rather, the output of the Python code will be code of a TeX source file.

*The website should then display the output of that TeX source (either as an image or pdf, but in the webpage -- not something to be downloaded by the user).

Any help greatly appreciated (specifically with the best way to implement the code in the website, and also if anyone knows a good way to do the 4th *)!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-02-20 18:06:21 -0600

Shashank gravatar image

Ok it is a bit late but I to look around the web a bit and here is what I found. If you have a web hosting server then you will have access to a directory called cgi-bin and public_html. In public_html keep the following file named test.html

<form method="get" action="./cgi-bin/test.cgi">
Input: <input type="text" name="name">
<input type="submit" value="Submit">

Now my cgi-bin is a subdirectory of public_html but change the path to whatever you have on your server. In cgi-bin keep a file test.cgi. The contents of test.cgi are as follows. You can import sage in the following script and use sage commands.

print "Content-Type: text/plain\n\n"
import cgi
form = cgi.FieldStorage() # instantiate only once!
name = form.getfirst('name', 'empty')
name = cgi.escape(name)
print """\
Content-Type: text/html\n
<p>Answer is "%s"</p>
""" % ans

Here the output is in html format but you can change it to make TeX. Input

image description


image description

edit flag offensive delete link more

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


Asked: 2012-02-20 07:45:33 -0600

Seen: 177 times

Last updated: Feb 20 '12