CoCalc Public Filespythontex-test / py.texOpen with one click!
Author: Harald Schilly
Views : 91
Description: pythontex
Compute Environment: Ubuntu 18.04 (Deprecated)
1
\documentclass{article}
2
3
% set font encoding for PDFLaTeX, XeLaTeX, or LuaTeX
4
\usepackage{ifxetex,ifluatex}
5
\newif\ifxetexorluatex
6
\ifxetex
7
\xetexorluatextrue
8
\else
9
\ifluatex
10
\xetexorluatextrue
11
\else
12
\xetexorluatexfalse
13
\fi
14
\fi
15
16
\ifxetexorluatex
17
\usepackage{fontspec}
18
\else
19
\usepackage[T1]{fontenc}
20
\usepackage[utf8]{inputenc}
21
\usepackage{lmodern}
22
\fi
23
24
\usepackage{lmodern}
25
26
\usepackage[margin=1in]{geometry}
27
\usepackage{microtype}
28
\usepackage{graphicx}
29
\usepackage{pythontex}
30
31
\usepackage[svgnames]{xcolor}
32
33
\usepackage{hyperref}
34
\hypersetup{colorlinks=true,urlcolor=Green,linkcolor=blue}
35
36
\newcommand{\pytex}{Python\TeX}
37
38
\begin{document}
39
40
\section{Testing PythonTeX}
41
42
\begin{pycode}
43
print(r'\begin{center}')
44
print(r'\textit{A message from Python!}')
45
print(r'\end{center}')
46
\end{pycode}
47
48
pyconsole test
49
50
\begin{pyconsole}
51
var = 1 + 1
52
var
53
\end{pyconsole}
54
55
\subsection{Symbolic computing with SymPy}
56
57
\begin{sympyblock}
58
phi = Symbol(r'\phi')
59
h = Integral(exp(-phi**2), (phi, 0, oo))
60
\end{sympyblock}
61
62
\[\sympy{h}=\sympy{h.doit()}\]
63
64
\subsection{Plotting}
65
66
\begin{pyconsole}
67
import matplotlib
68
matplotlib.use('pgf')
69
import numpy as np
70
import matplotlib.pyplot as plt
71
xx = np.random.randn(1000)
72
xx = np.sort(xx)
73
plt.plot(xx)
74
plt.savefig('myplot.pdf', bbox_inches='tight')
75
\end{pyconsole}
76
77
\begin{center}
78
\includegraphics{myplot.pdf}
79
\end{center}
80
81
\end{document}
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104