CoCalc Public Filespythontex-test / py.tex
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}
35
36\newcommand{\pytex}{Python\TeX}
37
38\begin{document}
39
40\section{Testing PythonTeX}
41
42\begin{pycode}
43print(r'\begin{center}')
44print(r'\textit{A message from Python!}')
45print(r'\end{center}')
46\end{pycode}
47
48pyconsole test
49
50\begin{pyconsole}
51var = 1 + 1
52var
53\end{pyconsole}
54
55\subsection{Symbolic computing with SymPy}
56
57\begin{sympyblock}
58phi = Symbol(r'\phi')
59h = 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}
67import matplotlib
68matplotlib.use('pgf')
69import numpy as np
70import matplotlib.pyplot as plt
71xx = np.random.randn(1000)
72xx = np.sort(xx)
73plt.plot(xx)
74plt.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