-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.tex
59 lines (45 loc) · 1.19 KB
/
example.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
% Compile with pdflatex -shell-escape
\documentclass{article}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{python}
\begin{document}
Here follows the result of some \href{http://www.python.org/}{Python} code.
\begin{itemize}
\begin{python}
# -*- coding: utf-8 -*-
#!/usr/bin/python
for i in range(10):
out = r"\item Le carr\'e de %s est %s car $%s \times %s=%s$"%(i, i*i,i,i,i*i)
print out
print r"\item etc."
\end{python}
\end{itemize}
You can also take advantage of
\href{http://code.google.com/p/sympy/}{SymPy}.
\begin{itemize}
\begin{python}
# -*- coding: utf-8 -*-
#!/usr/bin/python
from sympy import latex
from sympy import *
x,y = symbols('x,y')
def is_eqal(exp1, exp2):
exp1 = exp1.replace("$","")
exp2 = exp2.replace("$","")
return "$%s=%s$"%(exp1,exp2)
for el in ( (x+y)**2, (x+y)**3, (x+y)**4 ):
print r"\item[$\bullet$] " + is_eqal( latex(el), latex(el.expand()) )
\end{python}
\end{itemize}
Finally, you can include plots.
\begin{python}
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-np.pi, np.pi, 500)
y = np.sin(1/x)
plt.plot(x,y)
plt.savefig('myfig.pdf')
print r'\includegraphics[width=\linewidth]{myfig}'
\end{python}
\end{document}