\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{fullpage}
\usepackage{mathtools}
\usepackage{sagetex}
\usepackage{url}
\title{This is a demo of SageTeX}
\begin{document}
\maketitle
To learn more about \LaTeX: \url{https://en.wikibooks.org/wiki/LaTeX}
For SageTeX, please check out the project:
\url{https://github.com/dandrake/sagetex}
\section{Test}
Testing $\frac{1}{178} = \sage{n(1/178)}$.
\section{Plotting}
is always fun ...
\sageplot[width=.5\textwidth]{plot(x * (1+ sin(x)), (x,-10,10))}
\section{This is a test}
Testing $(1-x^2)^3 = \sage{((1-x^2)^2).expand()}$.
Using Sage\TeX, one can use Sage to compute things and put them into
your \LaTeX{} document. For example, there are
$\sage{number_of_partitions(1269)}$ integer partitions of $1269$.
You don't need to compute the number yourself, or even cut and paste
it from somewhere.
Here's some Sage code:
\begin{sageblock}
f(x) = cos(2*x)^2 / (2+x)
\end{sageblock}
The first derivative of $f$ is $\sage{diff(f,x)}$.
The second derivative of $f$ is
\[
\frac{\mathrm{d}^{2}}{\mathrm{d}x^{2}} \sage{f(x)} =
\sage{diff(f, x, 2)(x)}.
\]
Here's a plot of $f$ from $-1$ to $10$:
\sageplot[width=.5\textwidth]{plot(f, -1, 10)}
\section{AMS Math}
$$P\left(A=2\middle|\frac{A^2}{B}>4\right)$$
Matrix:
\begin{equation*}
A_{m,n} =
\begin{pmatrix}
a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\
a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{m,1} & a_{m,2} & \cdots & a_{m,n}
\end{pmatrix}
\end{equation*}
More here: \url{https://en.wikibooks.org/wiki/LaTeX/Mathematics}.
\section{Pure Text}
Usually, \verb|\sage{}| assumes that the value presented is
a mathematical formula and wraps it into \$.
Alternatively, one can display a Python-string via \verb|\sagestr{}|.
\begin{sagesilent}
u = 1 + 1
\end{sagesilent}
1+1 = \sagestr{str(u)}.
\end{document}