# Difference between revisions of "SageMath"

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Sage is a program for numerical and symbolic mathematical computation. It is meant to provide an alternative for commercial programs such as Maple, Matlab, and Mathematica. It is actually mantained in the community repository.

## Installation

Note: With version 4.8, the package sage-mathematicsAUR has been temporarily moved back to the AUR. Consider a compile- and build-time up to 4+ hours, depending on the performance of your system.

To install binaries from community repository:

# pacman -S sage-mathematics


## Usage

### Sage-Commandline

Once installed, users should be able to start the sage commandline in bash.

$sage  Math can then be typed at this commandline. sage: 2+2 4  Note, however, that the CLI is not very comforable for certain purposed. For instance, if you plot a function, sage: plot(sin,(x,0,10))  this is opened in a browser window. In these cases, you can start the notebook server by sage: notebook()  ### Sage-Notebook To start the Sage-Notebook server from bash, without going thru Sage-Commandline: $ sage -n


The notebook will be accessable in the browser from http://localhost:8000 , and will require you to login. However, If you are only intending to run the server for personal use, and not across the internet, the login will be an annoyance.

You can instead start Sage notebook without requiring login, and have it automatically pop up in a browser.

$BROWSER="chromium" sage -c "notebook(require_login=false,open_viewer=true)"  More detailed documentation can be read about the "notebook() command." ### Cantor The KDE Education Project includes a package called Cantor which acts as a front-end for several pieces of mathematical software including Sage. See: "Sage Wiki - Cantor page" "KDEEdu - Cantor page" You can install it with: $ pacman -S kdeedu-cantor


or along with the 'kde' or 'kdeedu' groups.

### Documentation

For local Documentation, one can compile it into html or even pdfs. Apparently, this needs to be executed as root (perhaps unsafely):

# sage -docbuild reference html


This builds html docs for the whole tree "reference" (which is alot; Expect many many hours). An option is to build a smaller part of the documentation tree, but you would need to know what it is you want. Until then, you might consider just browsing reference online. One place this can be found is at http://www.sagemath.org/doc/ .

### SageTeX

If you have installed Texlive on your system, you may be interested in using SageTeX, a package that makes possible the inclusion of sage code in LaTeX files. Starting from version 4.6.1-3, Texlive is made aware of SageTeX automagically, and you can start using it straight away.

As a simple example, here is how you include a Sage 2D plot in your latex document (assuming you use pdfLaTeX):

• include the sagetex package in the preamble of your document with the usual
\usepackage{sagetex}

• create a sagesilent environment in which you insert your sage code:
\begin{sagesilent}
dob(x) = sqrt(x^2-1)/(x * arctan(sqrt(x^2-1)))
dpr(x) = sqrt(x^2-1)/(x * log( x + sqrt(x^2-1)))
p1 = plot(dob,(x,1,10),color='blue')
p2 = plot(dpr,(x,1,10),color='red')
ptot=p1+p2
ptot.axes_labels(['$\\xi$','$\\frac{R_h}{\\max(a,b)}$'])
\end{sagesilent}

• create the plot e.g. inside a float environment:
\begin{figure}
\begin{center}
\sageplot[width=\linewidth]{ptot}
\end{center}
\end{figure}

• compile your document with the following procedure:
$pdflatex <doc.tex>$sage <doc.sage>
\$pdflatex <doc.tex>

• you can have a look at your output document.

The full documentation of SageTeX is available on CTANTemplate:Linkrot.

#### Troubleshooting

If your Texlive installation does not find the sagetex package, you can try the following procedure (do it as root, or with sudo, or use a local folder):

• Copy the files to the texmf directory:
# cp /opt/sage/local/share/texmf/tex/* /usr/share/texmf/tex/

• Refresh Texlive:
# texhash /usr/share/texmf/
texhash: Updating /usr/share/texmf/.//ls-R...
texhash: Done.