Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 1949
1
\documentclass{article}
2
3
\usepackage[utf8]{inputenc}
4
\usepackage{fullpage}
5
\usepackage{mathtools}
6
\usepackage{sagetex}
7
\usepackage{url}
8
9
\title{This is a demo of SageTeX}
10
11
\begin{document}
12
13
\maketitle
14
15
To learn more about \LaTeX: \url{https://en.wikibooks.org/wiki/LaTeX}
16
17
For SageTeX, please check out the project:
18
\url{https://github.com/dandrake/sagetex}
19
20
\section{Test}
21
22
Testing $\frac{1}{178} = \sage{n(1/178)}$.
23
24
\section{Plotting}
25
26
is always fun ...
27
28
\sageplot[width=.5\textwidth]{plot(x * (1+ sin(x)), (x,-10,10))}
29
30
\section{This is a test}
31
32
Testing $(1-x^2)^3 = \sage{((1-x^2)^2).expand()}$.
33
34
Using Sage\TeX, one can use Sage to compute things and put them into
35
your \LaTeX{} document. For example, there are
36
$\sage{number_of_partitions(1269)}$ integer partitions of $1269$.
37
You don't need to compute the number yourself, or even cut and paste
38
it from somewhere.
39
40
Here's some Sage code:
41
42
\begin{sageblock}
43
f(x) = cos(2*x)^2 / (2+x)
44
\end{sageblock}
45
46
The first derivative of $f$ is $\sage{diff(f,x)}$.
47
48
The second derivative of $f$ is
49
50
\[
51
\frac{\mathrm{d}^{2}}{\mathrm{d}x^{2}} \sage{f(x)} =
52
\sage{diff(f, x, 2)(x)}.
53
\]
54
55
Here's a plot of $f$ from $-1$ to $10$:
56
57
\sageplot[width=.5\textwidth]{plot(f, -1, 10)}
58
59
\section{AMS Math}
60
61
$$P\left(A=2\middle|\frac{A^2}{B}>4\right)$$
62
63
Matrix:
64
65
\begin{equation*}
66
A_{m,n} =
67
\begin{pmatrix}
68
a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\
69
a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\
70
\vdots & \vdots & \ddots & \vdots \\
71
a_{m,1} & a_{m,2} & \cdots & a_{m,n}
72
\end{pmatrix}
73
\end{equation*}
74
75
More here: \url{https://en.wikibooks.org/wiki/LaTeX/Mathematics}.
76
77
\section{Pure Text}
78
79
Usually, \verb|\sage{}| assumes that the value presented is
80
a mathematical formula and wraps it into \$.
81
Alternatively, one can display a Python-string via \verb|\sagestr{}|.
82
83
\begin{sagesilent}
84
u = 1 + 1
85
\end{sagesilent}
86
87
1+1 = \sagestr{str(u)}.
88
89
\end{document}
90
91