A few minuted ago I could install and use the sagetex package for Sage(math). I’d like to thank **ElMonkey** for helping me via the IRC channel *#sage-devel*.

## Pre-requisites.

It is assumed that you have installed

- A LaTeX compiler,
- A LaTeX editor,
- and Sage(math)

all of them configured and working properly.

## Downloading the Package.

Get the last version of the package in http://www.sagemath.org/packages/optional/.

## Installing the Package.

### Useful Advise.

My Sage script is located in a sub/sub/sub/subfolder/Sage-4.3.1 (from my HOME folder), so when I want to running it, I should type

$ sub/sub/sub/subfolder/Sage-4.3.1/./sage

It isn’t nice to repeat this one and again, every day.

Thus, I created an alias.

Open the .bashrc file in your editor (gedit for example)

$ gedit .bashrc

add (at the end of the file) the line

alias sage='/path/to/your/sage/folder/./sage'

which in my example would be,

alias sage='/home/doxdrum/sub/sub/sub/subfolder/Sage-4.3.1/./sage'

Save and close the editor. Now in the terminal,

$ source .bashrc

and from now on I just type

$ sage

for running the program.

### The real installation.

Now, type in the terminal

$ sage -i sagetex-2.2.1.spkg

and that’s it.

## Configuration.

After the installation, a new folder is placed into the Sage folder. Look into *local/share/texmf*. All files (and folders) inside it must be copied to the LaTeX tree.

In a Linux distribution the LaTeX tree should be placed in /usr/share/texmf/tex/latex

$ sudo cp -r /path/to/Sage-4.3.1/local/share/texmf \ /usr/share/texmf/tex/latex $ sudo mktexlsr /usr/share/texmf/tex/latex

This should work. However, if it doesn’t… the desperate method is to copy the *sagetex.sty* from */path/to/Sage-4.3.1/local/share/texmf* to the folder of the TEX file.

## The TeX File.

It is time to create a file.tex, just as any other TEX file. Add the line

\usepackage{sagetex}

to the preable.

### Compiling the TeX file.

When you run

$ pdflatex file.tex

the compilator exits with errors… but you get a file.sage, sage-compile it and run pdflatex again,

$ sage file.sage $ pdflatex file.tex

There it is!!!

A resume compilation line could be

$ pdflatex file.tex && sage file.sage && pdflatex file.tex

Enjoy it!

on February 4, 2010 at 7:13 pm |mvnguSageTeX will be a standard package in the upcoming Sage 4.3.2 release. So no need to install SageTeX separately any longer.

on February 4, 2010 at 11:42 pm |DanInstead of copying the texmf directory into /usr/share/texmf/tex/latex, I recommend copying it into your home directory. Then you don’t need to use sudo and, with modern TeX distributions, you also don’t need to use mktexlsr. Just copy the directory to ~/ and it should work:

cp -r /path/to/Sage-4.3.1/local/share/texmf ~/

Anything inside ~/texmf should be automatically found by TeX.

on February 4, 2010 at 11:49 pm |Dan(Hmm, my first comment seems to have disappeared…)

I recommend copying the texmf directory into your home directory, and not /usr/share/texmf. Then you don’t need to use sudo, and don’t need to run mktexlsr. Just doing

cp -r /path/to/Sage-4.3.1/local/share/texmf ~/

should work if you are using any reasonable TeX distribution. It won’t overwrite your other files in ~/texmf, and TeX will automatically find the files without running mktexlsr.

on February 4, 2010 at 11:52 pm |doxdrumThe first didn’t disappear, you should wait for my approval 😉

Thank you the your clarification.

on February 6, 2010 at 12:12 pm |lilai have texmaker but now i prefer to use this package sagetex.cause it’s easier

on February 10, 2013 at 6:19 am |MatthiasThx,

$ pdflatex file.tex

$ sage file.sage

$ pdflatex file.tex

solved my problem. Now i’ve got the desired output. It’s a pity there is “there’s no convenient way to produce vector graphics.” But i haven’t tried to produce them yet…