Ask Your Question
2

Implementing Sage on Website

asked 2012-02-20 14:45:33 +0100

anonymous user

Anonymous

updated 2012-02-20 22:42:24 +0100

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
0

answered 2012-02-21 01:06:21 +0100

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

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

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.

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

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

image description

Output

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

Stats

Asked: 2012-02-20 14:45:33 +0100

Seen: 515 times

Last updated: Feb 21 '12