SageCell

Summary: This allows you to embed an interactive SageCell into your webpage. Sage is an open source alternative to MathLab, Mathematica, and Maple.
Version: 2013-10-10
Prerequisites: None
Status: Stable
Maintainer: Ben Woodruff
Categories: Math
Users: (view? / edit)
Discussion: SageCell-Talk?

Questions answered by this recipe

Can I embed a sagecell into my wiki so that users can perform mathematical computations on the fly?

Installation

You can either copy/paste the following to your config.php file, or you can create a cookbook file and add it there. If someone would like to create a cookbook php file, fix any PHP issues I may have introduced, and upload the file here, feel free.

  Markup('sage', 'directives', '/\\(:sage:\\)/i', '<div class="sage">');
  Markup('sageend', 'directives', '/\\(:sageend:\\)/i', '</div>');
  $HTMLHeaderFmt['SageCell'] = '
   <script src="https://sagecell.sagemath.org/static/jquery.min.js"></script>
   <script src="https://sagecell.sagemath.org/static/embedded_sagecell.js"></script>
   <script>
    $(function () {
        // Make *any* div with class "sage" a Sage cell
        sagecell.makeSagecell({inputLocation: "div.sage",
                               evalButtonText: "Evaluate"});
    });
   </script>
  ';

Feel free to add any CSS you want to change the style.

Usage

Just type (:sage:) to start a computation block, and then type (:sageend:) to end one. Here's an example:

(:sage:)
var('x,y')
f(x)=x^2
plot(f,(x,-3,5))
(:sageend:)

Sometimes there are issues if you use comments in your sage code. Using the syntax (:sage:)[@ and @](:sageend:) fixes these issues (I don't know how to program this to be the default).

See also

http://wstein.org/edu/2012/1062/sagecell/

Contributors

Ben Woodruff

Comments

See discussion at SageCell-Talk?

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.