\documentclass{article}

% see http://www.sagemath.org/doc/tutorial/sagetex.html
% for more information on sagetex
\usepackage{sagetex}

\title{Using \LaTeX\ with Sage}
\author{Armin Straub}

\begin{document}
\maketitle

This is just a quick example tex file.  Isn't Euler's formula for $\zeta(2)$ beautiful?
$$ \sum_{n=1}^\infty \frac{1}{n^2} = \frac{\pi^2}{6} $$

Using the package \texttt{sagetex}, we can let Sage compute for us: $2^8 = \sage{2^8}$

More interestingly, how about letting Sage produce more terms of $\zeta(s)$ when $s$ is an even integer?
$$ \sage{[zeta(2*n) for n in [1..5]]} $$

Or, say, we are interested in the power series of the Bernoulli-like generating function $\frac12 x^2/(e^x-1-x)$. Sage reports that this series is:
\begin{sagesilent}
    R.<x> = QQ[[]]
    R.set_default_prec(8)
\end{sagesilent}
$$ \sage{(x^2/2/(e^x-1-x))} $$
% Note that we redefined the symbolic variable x above to be the generator of a power series ring. Let's undo that to avoid confusion later.
\begin{sagesilent}
    x = var('x')
\end{sagesilent}

% Note that we could have also used the series command in the symbolic ring. However, the output doesn't quite look as nice, and we are dealing with an honest power series.
%$$ \sage{(x^2/(e^x-1-x)).series(x,6)}. $$


Sage code can be conveniently displayed (and executed) using \texttt{sageblock}:
\begin{sageblock}
    A=matrix([[1,2,3],[4,5,7]])
\end{sageblock}
You can use \texttt{sagesilent}, as we actually did above, instead of \texttt{sageblock} if you do not want to produce any output.

The row-reduced echelon form of $A$ is $\sage{A.rref()}$.

Look into \texttt{sageplot} if you are interested in letting Sage create pictures (of any kind) for you.
$$\sageplot[width=.4\textwidth]{plot((x^2/2/(e^x-1-x)), x, -pi, pi)} \qquad \sageplot[width=.35\textwidth]{graphs.PetersenGraph().plot()}$$

Have fun!

% For many more examples of sagetex check out the example.tex file at https://github.com/dandrake/sagetex.

\end{document}
