Section 4.22 Sage
Until we can expand this section, get some ideas from Section 3.17. We will also collect a few items here, to be cleaned-up later.
For online output formats, sometimes the output of a Sage command can be overwhelming, and a bit complicated to parse. Many objects in Sage also have a LaTeX representation, which can be used to create a superior output format (for some purposes). Begin a cell with the “magic”:
%display latex
Experiment with the following Sage code on the next line
integral(x^9*cos(x), x)
Boom! Very nice. Try replacing
latex
with None
, plain
, ascii_art
, or unicode_art
.Subsection 4.22.1 Sage Cell Server Design
The ability to execute, and edit, chunks of Sage code is provided by a distinct project, the Sage Cell Server. Simplifying somewhat, the Sage code a reader sees (or has edited!) is shipped out to a running instance of Sage (on a server somewhere) and the code is executed there. The results of that computation are shipped back to the reader for display below the code.
1
sagecell.sagemath.org/
Two implications of this design are
- It is not within your power to add additional packages for the supported languages.
- You cannot read a (data) file hosted on your project’s site.
Fortunately, there are workarounds.
If your code needs a Python package, or an R package, or similar, and it is a standard open source package, then make a request on the Sage Cell Google Group. Likely, it can be added/installed.
2
groups.google.com/g/sage-cell
Unfortunately, the ability to read files anywhere on the internet was abused, so this capability had to be restricted to a finite list of servers. These include DropBox and GitHub where you might find it convenient to place files supporting your code. Note that for GitHub, you likely want to use a URL which is a “raw” file such as for the PreTeXt repository README file, written with Markdown.
3
www.dropbox.com
4
github.com
5
github.com/PreTeXtBook/pretext/raw/master/README.md