Firstly install Sagetex. For this open terminal and give the following commands.

priyanka@ubuntu:-~$

sage -i sagetex-2.0.1 sudo apt-get install texlive-full wget http://ctan.mackichan.com/info/epslatex/french/makecmds.sty vi priya.tex

Here sage -i sagetex-version, where version can be any latest version.

Type in the following code:

\documentclass{article} \title{Analysis and Design by SAGE in \LaTeX} \author{Priyanka Kapoor} \usepackage{sagetex}\begin{document} \maketitle \begin{sageblock} A(l,b) = l*b l = 2 b= 4 area = A(l,b) \end{sageblock} Using formula \[ A = \sage{latex(A(l,b))} \] for area $A = \sage{area.n(digits=2)}$ \end{document} PressEscapethen:wq(Save and quit from vi editor)

Now write a script for running sage with latex. Here are its contents:

vi priya.sh#!/bin/bash cd latex priya.tex sage priya.sagetex.sage pdflatex priya.tex evince priya.pdf

Press **Escape** then type** :wq**

Now run the script by the following command.

./priya.sh

All commands will be executed and you will get a pdf file showing the result of program.

**Note:**

If** evince file_name** don’t work then try** acroread file_name**

Problem Faced By Me:

Usually when you upgarde your sage version then there is possibility of one basic problem that:

sagetex.sty file of sage and sagetex.sty file of texlive are of different versions. So whenn we run command latex filename.tex, it compile and give filename.sagetex.sage . Now to compile this, we do sage filename.sagetex.sage. Here it gives error that

filename.sagetex.sage was generated by sagetex.sty version “None”, but

is being processed by sagetex.py version “2012/01/16 v2.3.3-69dcb0eb93de”.

Please make sure that TeX is using the sagetex.sty

from your current version of Sage.

To solve this:

1. Firstly remove sagetex.sty file of Tex from /usr/share/texmf-texlive/tex/latex/sagetex.

to make TeX aware of `sagetex.sty` is to copy that file into a convenient place in your home directory. In most TeX distributions, the `texmf`directory in your home directory is automatically searched for packages. To find out exactly what this directory is, do the following on the command line:

kpsewhich -var-value=TEXMFHOME

which will print out a directory, such as `/home/priyanka/texmf` or `/Users/drake/Library/texmf`. Copy the `tex/` directory from `SAGE_ROOT/local/share/texmf/` into your home `texmf` directory with a command like (SAGE_ROOT=/home/priyanka/sage)

cp -R SAGE_ROOT/local/share/texmf/tex TEXMFHOME

where `SAGE_ROOT` is, as usual, replaced with the location of your Sage installation and `TEXMFHOME` is the result of the `kpsewhich` command above.

Check home folder, is there any texmf folder? If not , then TEXMFHOME will surely there. Rename it to texmf and now sagetex is known to tex.

If you upgrade Sage and discover that SageTeX no longer works, you can simply repeat these steps and the Sage and TeX parts of SageTeX will again be synchronized.

For more reference:

https://groups.google.com/forum/?fromgroups#!topic/sage-support/0_ySEucndFU

http://www.sagemath.org/doc/installation/sagetex.html

A very informative tutorial indeed.

After a sage upgrade, and having followed your instructions I still am having a certain problem.

I have a simple tex file “Test.tex” with a plot function.

If I try ………

geralt@localhost:~/Documents$ sage Test.sagetex.sage

Processing Sage code for Test.tex…

Inline formula 0

Code block begin…end

Inline formula 1

Inline formula 2

Inline formula 3

Inline formula 4

Initializing plots directory

**** Error in Sage code on line 39 of Test.tex! Traceback follows.

Traceback (most recent call last):

File “Test.sagetex.py”, line 34, in

_st_.plot(_sage_const_0 , format=’notprovided’, _p_=plot(sin(x),-_sage_const_0p5 , _sage_const_0p5 ))

File “/usr/lib/sagemath/local/lib/python2.7/site-packages/sagetex.py”, line 237, in plot

self.initplot()

File “/usr/lib/sagemath/local/lib/python2.7/site-packages/sagetex.py”, line 98, in initplot

shutil.rmtree(self.plotdir)

File “/usr/lib/sagemath/local/lib/python/shutil.py”, line 250, in rmtree

onerror(os.remove, fullname, sys.exc_info())

File “/usr/lib/sagemath/local/lib/python/shutil.py”, line 248, in rmtree

os.remove(fullname)

OSError: [Errno 13] Permission denied

**** Running Sage on Test.sage failed! Fix Test.tex and try again.

geralt@localhost:~/Documents$

But with sudo………

geralt@localhost:~/Documents$ sudo sage Test.sagetex.sage

[sudo] password for geralt:

Processing Sage code for Test.tex…

Inline formula 0

Code block begin…end

Inline formula 1

Inline formula 2

Inline formula 3

Inline formula 4

Initializing plots directory

Plot 0

Sage processing complete. Run LaTeX on Test.tex again.

geralt@localhost:~/Documents$

I guess I have to change permissions somewhere, but I can’t figure out anything else.

I would be highly obliged if you can suggest a fix.