diff options
Diffstat (limited to 'Master/texmf-dist/doc/latex')
-rw-r--r-- | Master/texmf-dist/doc/latex/pythontex/README | 68 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/pythontex/pythontex.pdf | bin | 0 -> 887905 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/latex/pythontex/pythontex_gallery.pdf | bin | 0 -> 382386 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/latex/pythontex/pythontex_gallery.tex | 287 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/pythontex/pythontex_quickstart.pdf | bin | 0 -> 79542 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/latex/pythontex/pythontex_quickstart.tex | 93 |
6 files changed, 448 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/latex/pythontex/README b/Master/texmf-dist/doc/latex/pythontex/README new file mode 100644 index 00000000000..3c7247e9dcf --- /dev/null +++ b/Master/texmf-dist/doc/latex/pythontex/README @@ -0,0 +1,68 @@ +=================================================================== + The PythonTeX Package +=================================================================== + +:Author: Geoffrey Poore +:Version: 0.12 (2013/08/26) +:License: LPPL v1.3 or later (LaTeX code) and BSD 3-Clause (Python code) +:Development: https://github.com/gpoore/pythontex +:Requirements: Python 2.7 or 3.2+; Pygments + + +The PythonTeX package allows you to enter Python code within a LaTeX +document, execute the code, and access its output in the original document. +Since v0.12, it also supports the Ruby and Julia languages. + +PythonTeX provides fast, user-friendly access to Python from within LaTeX. +Python code is only executed when it has been modified, or when it meets +user-specified criteria. Code may be divided into user-defined sessions, +which automatically run in parallel. Errors and warnings are synchronized +with the LaTeX document, so that they refer to the document's line numbers. +External dependencies can be tracked, so that code is re-executed when the +data it depends on is modified. PythonTeX also provides syntax highlighting +for code in LaTeX documents via the Pygments syntax highlighter. + +PythonTeX includes a "depythontex" utility that creates a copy of a document +in which all Python code has been replaced by its output. This can be +convenient for journal submissions, sharing documents, and converting to +other formats. + +Consult pythontex_quickstart.pdf and pythontex_gallery.pdf to get +started and for examples of what PythonTeX can do. + +Compiling a PythonTeX document involves three steps: + +1. Run latex (all Python code is saved to an auxiliary file) +2. Run pythontex.py (all code is executed) +3. Run latex again (Python output is inputted) + +See the main documentation in pythontex.pdf for detailed installation +instructions. An installation script is provided for TeX Live. Files +should be installed in the directories indicated below. In summary, +all files must be installed, and symlinks or launching wrappers should be +created for pythontex.py and depythontex.py. + +* /doc/latex/pythontex/ + + - pythontex.pdf + - README + - pythontex_quickstart.tex + - pythontex_quickstart.pdf + - pythontex_gallery.tex + - pythontex_gallery.pdf + +* /scripts/pythontex/ + + - pythontex.py, pythontex2.py, and pythontex3.py + - pythontex_engines.py + - pythontex_utils.py + - depythontex.py, depythontex2.py, and depythontex3.py + +* /source/latex/pythontex/ + + - pythontex.dtx + - pythontex.ins + +* /tex/latex/pythontex/ + + - pythontex.sty diff --git a/Master/texmf-dist/doc/latex/pythontex/pythontex.pdf b/Master/texmf-dist/doc/latex/pythontex/pythontex.pdf Binary files differnew file mode 100644 index 00000000000..4d3c8661c6b --- /dev/null +++ b/Master/texmf-dist/doc/latex/pythontex/pythontex.pdf diff --git a/Master/texmf-dist/doc/latex/pythontex/pythontex_gallery.pdf b/Master/texmf-dist/doc/latex/pythontex/pythontex_gallery.pdf Binary files differnew file mode 100644 index 00000000000..66ba25e6e4f --- /dev/null +++ b/Master/texmf-dist/doc/latex/pythontex/pythontex_gallery.pdf diff --git a/Master/texmf-dist/doc/latex/pythontex/pythontex_gallery.tex b/Master/texmf-dist/doc/latex/pythontex/pythontex_gallery.tex new file mode 100644 index 00000000000..29feb22c309 --- /dev/null +++ b/Master/texmf-dist/doc/latex/pythontex/pythontex_gallery.tex @@ -0,0 +1,287 @@ +\documentclass[11pt]{article} + +% Engine-specific settings +% Detect pdftex/xetex/luatex, and load appropriate font packages. +% This is inspired by the approach in the iftex package. +% pdftex: +\expandafter\ifx\csname pdfmatch\endcsname\relax +\else + \usepackage[T1]{fontenc} + \usepackage[utf8]{inputenc} +\fi +% xetex: +\expandafter\ifx\csname XeTeXinterchartoks\endcsname\relax +\else + \usepackage{fontspec} + \defaultfontfeatures{Ligatures=TeX} +\fi +% luatex: +\expandafter\ifx\csname directlua\endcsname\relax +\else + \usepackage{fontspec} +\fi +% End engine-specific settings + +\usepackage{amsmath,amssymb} +\usepackage{fullpage} +\usepackage{graphicx} +\usepackage[svgnames]{xcolor} +\usepackage{url} +\urlstyle{same} + +\usepackage[makestderr]{pythontex} +\restartpythontexsession{\thesection} + + +\usepackage[framemethod=TikZ]{mdframed} + +\newcommand{\pytex}{Python\TeX} +\renewcommand*{\thefootnote}{\fnsymbol{footnote}} + + +\title{\pytex\ Gallery} +\author{Geoffrey M.\ Poore} + + +\begin{document} + + +\maketitle + + +\begin{abstract} +\pytex\ allows you to run Python code from within \LaTeX\ documents and automatically include the output. This document serves as an example of what is possible with \pytex.\footnote{Since \pytex\ runs Python code (and potentially other code) on your computer, documents using \pytex\ have a greater potential for security risks than do standard \LaTeX\ documents. You should only compile \pytex\ documents from sources you trust.} +\end{abstract} + + + +\section{General Python interaction} + +We can typeset code that is passed to Python, and bring back the results. + +This can be simple. For example, \pyb{print('Python says hi!')} returns the following: +\begin{quote} +\printpythontex +\end{quote} + +Or we could access the printed content verbatim (it might contain special characters): +\begin{quote} +\printpythontex[verb] +\end{quote} + +Python interaction can also be more complex. \pyb{print(str(2**2**2) + r'\endinput')} returns \printpythontex. In this case, the printed results include \LaTeX\ code, which is correctly interpreted by \LaTeX\ to ensure that there is not an extra space after the 16. Printed output is saved to a file and brought back in via \verb|\input|, and the \verb|\endinput| command stops input immediately, before \LaTeX\ gets to the end of the line and inserts a space character there, after the 16. + +Printing works, but as the last example demonstrates, you have to be careful about spacing if you have text immediately after the printed content. In that case, it's usually best to assemble text within a \pytex\ environment and store the text in a variable. Then you can bring in the text later, using the \pygment{latex}{\py} command. The \pygment{latex}{\py} command brings in a string representation of its argument. First we create the text. +\begin{pyblock} +mytext = '$1 + 1 = {0}$'.format(1 + 1) +\end{pyblock} +Then we bring it in: \py{mytext}. The \pygment{latex}{\py} command can even bring in verbatim content, as long as you are using the pdfTeX or XeTeX engines. (Unfortunately, verbatim does not work with LuaTeX, due to a bug.\footnote{\url{http://tracker.luatex.org/view.php?id=733}}) + +We don't have to typeset the code we're executing. It can be hidden.\pyc{mystring=r'\textbf{This is a message from Python}'} And then we can access it later: \py{mystring}. + + +\section{Pygments highlighting} + +\pytex\ supports syntax highlighting via Pygments. Any language supported by Pygments can be highlighted. Unicode is supported. Consider this snippet copied and pasted from a Python 3 interactive session. (Using random strings of Unicode for variable names is probably not a good idea, but \pytex\ will happily highlight it for you.) + +\begin{pygments}{pycon} +>>> âæéöø = 123 +>>> ßçñðŠ = 456 +>>> âæéöø + ßçñðŠ +579 +\end{pygments} + +There is also a Pygments command for inline use: \pygment{latex}{\pygment}. + + +\section{Python console environment} + +\pytex\ includes an environment that emulates a Python interactive session. Commands are entered within the environment, each line is treated as input to an interactive session, and the result is typeset. + +\begin{pyconsole}[][frame=single] +x = 123 +y = 345 +z = x + y +z +def f(expr): + return(expr**4) + +f(x) +print('Python says hi from the console!') +\end{pyconsole} + +It is possible to refer to the values of console variables later on in inline contexts, using the \pygment{latex}{\pycon} command. For example, the value of $z$ was \pycon{z}. + + +\section{Basic SymPy interaction} + +\pytex\ allows us to perform algebraic manipulations with SymPy and then properly typeset the results. + +We create three variables, and define $z$ in terms of the other two. + +\begin{sympyblock} +var('x, y, z') +z = x + y +\end{sympyblock} + +Now we can access what $z$ is equal to: + +\[z=\sympy{z}\] + +Many things are possible, including some very nice calculus. + +\begin{sympyblock} +f = x**3 + cos(x)**5 +g = Integral(f, x) +\end{sympyblock} + +\[\sympy{g}=\sympy{g.doit()}\] + +It's easy to use arbitrary symbols in equations. + +\begin{sympyblock} +phi = Symbol(r'\phi') +h = Integral(exp(-phi**2), (phi, 0, oo)) +\end{sympyblock} + +\[\sympy{h}=\sympy{h.doit()}\] + + + +\section{Plots with matplotlib} + +We can create plots with matplotlib, perfectly matching the plot fonts with the document fonts. No more searching for the code that created a figure! + +You may want to use matplotlib's PGF backend when creating plots. + +\begin{pylabblock} +rc('text', usetex=True) +rc('font', family='serif') +rc('font', size=10.0) +rc('legend', fontsize=10.0) +rc('font', weight='normal') +x = linspace(0, 10) +figure(figsize=(4, 2.5)) +plot(x, sin(x), label='$\sin(x)$') +xlabel(r'$x\mathrm{-axis}$') +ylabel(r'$y\mathrm{-axis}$') +legend(loc='lower right') +savefig('myplot.pdf', bbox_inches='tight') +\end{pylabblock} + +\begin{center} +\includegraphics{myplot.pdf} +\end{center} + + +\section{Basic pylab interaction} + +\begin{pylabblock} +from scipy.integrate import quad +myintegral = quad(lambda x: e**-x**2, 0, inf)[0] +\end{pylabblock} + +\[ \int_0^\infty e^{-x^2}\,dx = \pylab{myintegral} \] + + +\section{An automated derivative and integral table} + +\pytex\ allows some amazing document automation, such as this derivative and integral table. Try typing that by hand, fast! + +\begin{sympyblock}[][numbers=left,frame=single,framesep=5mm,label=An Automated Derivative and Integral Table] +from re import sub + +var('x') + +# Create a list of functions to include in the table +funcs = ['sin(x)', 'cos(x)', 'tan(x)', + 'sin(x)**2', 'cos(x)**2', 'tan(x)**2', + 'asin(x)', 'acos(x)', 'atan(x)', + 'sinh(x)', 'cosh(x)', 'tanh(x)'] + +print(r'\begin{align*}') + +for func in funcs: + # Put in some vertical space when switching to arc and hyperbolic funcs + if func == 'asin(x)' or func == 'sinh(x)': + print(r'&\\') + myderiv = 'Derivative(' + func + ', x)' + myint = 'Integral(' + func + ', x)' + print(latex(eval(myderiv)) + '&=' + + latex(eval(myderiv + '.doit()')) + r'\quad & \quad') + print(latex(eval(myint)) + '&=' + + latex(eval(myint+'.doit()')) + r'\\') +print(r'\end{align*}') +\end{sympyblock} + +\printpythontex + + +\section{Step-by-step solutions} + +Using SymPy, it is possible to typeset step-by-step solutions. In this particular case, we also use the \verb|mdframed| package to place a colored background behind our code. + +\begin{mdframed}[linecolor=Green,innerrightmargin=30pt,innerleftmargin=30pt,leftmargin=-30pt,rightmargin=-30pt,backgroundcolor=Black!5,skipabove=10pt,skipbelow=10pt,roundcorner=5pt,frametitle={Step-by-Step Integral Evaluation},frametitlealignment=\center,splitbottomskip=6pt,splittopskip=12pt] +\begin{sympyblock}[][numbers=left] +x, y, z = symbols('x,y,z') +f = Symbol('f(x,y,z)') + +# Define limits of integration +x_llim = 0 +x_ulim = 2 +y_llim = 0 +y_ulim = 3 +z_llim = 0 +z_ulim = 4 + +print(r'\begin{align*}') + +# Notice how I define f as a symbol, then later as an actual function +left = Integral(f, (x, x_llim, x_ulim), (y, y_llim, y_ulim), (z, z_llim, z_ulim)) +f = x*y + y*sin(z) + cos(x+y) +right = Integral(f, (x, x_llim, x_ulim), (y, y_llim, y_ulim), (z, z_llim, z_ulim)) +print(latex(left) + '&=' + latex(right) + r'\\') + +# For each step, I move limits from an outer integral to an inner, evaluated +# integral until the outer integral is no longer needed +right = Integral(Integral(f, (z, z_llim, z_ulim)).doit(), (x, x_llim, x_ulim), + (y, y_llim, y_ulim)) +print('&=' + latex(right) + r'\\') + +right = Integral(Integral(f, (z, z_llim, z_ulim), (y, y_llim, y_ulim)).doit(), + (x, x_llim, x_ulim)) +print('&=' + latex(right) + r'\\') + +right = Integral(f, (z, z_llim, z_ulim), (y, y_llim, y_ulim), + (x, x_llim, x_ulim)).doit() +print('&=' + latex(right) + r'\\') + +print('&=' + latex(N(right)) + r'\\') + +print(r'\end{align*}') +\end{sympyblock} +\end{mdframed} + +\printpythontex + + +\section{Including stderr} + +\pytex\ allows code to be typset next to the stderr it produces. This requires the package option \verb|makestderr|. + +\begin{pyblock}[errorsession][numbers=left] +x = 123 +y = 345 +z = x + y + +\end{pyblock} + +This code causes a syntax error: + +\stderrpythontex[verbatim][frame=single] + +The package option \verb|stderrfilename| allows the file name that appears in the error message to be customized. + + + + +\end{document} diff --git a/Master/texmf-dist/doc/latex/pythontex/pythontex_quickstart.pdf b/Master/texmf-dist/doc/latex/pythontex/pythontex_quickstart.pdf Binary files differnew file mode 100644 index 00000000000..cacc158dce4 --- /dev/null +++ b/Master/texmf-dist/doc/latex/pythontex/pythontex_quickstart.pdf diff --git a/Master/texmf-dist/doc/latex/pythontex/pythontex_quickstart.tex b/Master/texmf-dist/doc/latex/pythontex/pythontex_quickstart.tex new file mode 100644 index 00000000000..41d4f43b33b --- /dev/null +++ b/Master/texmf-dist/doc/latex/pythontex/pythontex_quickstart.tex @@ -0,0 +1,93 @@ +\documentclass[twocolumn]{article} + +\usepackage[margin=1in]{geometry} +\usepackage{microtype} + +\usepackage{pythontex} + +\usepackage[svgnames]{xcolor} + +\usepackage{nopageno} + +\usepackage{hyperref} +\hypersetup{colorlinks=true,urlcolor=Green,linkcolor=blue} + +\newcommand{\pytex}{Python\TeX} +\renewcommand*{\thefootnote}{\fnsymbol{footnote}} + +\title{\vspace{-0.6in} \pytex\ Quickstart \\ {\normalsize \href{https://github.com/gpoore/pythontex}{github.com/gpoore/pythontex}}} +\author{} +\date{} + + +\begin{document} + + +\maketitle + + + + +\section*{Compiling} + +Compiling a document that uses \pytex\ involves three steps: run latex, run \texttt{pythontex.py}, and finally run latex again. You may wish to create a symlink or launching wrapper for \texttt{pythontex.py}, if one was not created during installation. \pytex\ is compatible with the pdfLaTeX, XeLaTeX, and LuaLaTeX engines. There are minor engine-specific differences. + + +\section*{Commands} + +\pygment{latex}{\py} returns a string representation of its argument. For example, \pygment{latex}{\py{2 + 4**2}} produces \py{2 + 4**2}, and \pygment{latex}{\py{'ABC'.lower()}} produces \py{'ABC'.lower()}. \pygment{latex}{\py}'s argument can be delimited by curly braces, or by a matched pair of other characters (just like \pygment{latex}{\verb}). + +\pygment{latex}{\pyc} executes code. By default, anything that is printed is automatically included in the document (see \texttt{autoprint}/\texttt{autostdout} in the main documentation). For example, \pygment{latex}{\pyc{var = 2}} \pyc{var = 2} creates a variable, and then its value may be accessed later via \pygment{latex}{\py{var}}: \py{var}. + +\pygment{latex}{\pyb} executes and typesets code. For example, \pygment{latex}{\pyb{var = 2}} typesets \pyb{var = 2} in addition to creating the variable. If anything is printed, it is not automatically included, but can be accessed via \pygment{latex}{\printpythontex} and \pygment{latex}{\stdoutpythontex}. + +\pygment{latex}{\pyv} only typesets code. For example, \pygment{latex}{\pyv{var = 2}} produces \pyv{var = 2}. + + +\section*{Environments} + +There are \texttt{pycode}, \texttt{pyblock}, and \texttt{pyverbatim} environments, which are the environment equivalents of \pygment{latex}{\pyc}, \pygment{latex}{\pyb}, and \pygment{latex}{\pyv}. For example, +\begin{pygments}{text} +\begin{pycode} +print(r'\begin{center}') +print(r'\textit{A message from Python!}') +print(r'\end{center}') +\end{pycode} +\end{pygments} +produces +\begin{pycode} +print(r'\begin{center}') +print(r'\textit{A message from Python!}') +print(r'\end{center}') +\end{pycode} + +There is also a \texttt{pyconsole} environment that emulates a Python interactive console. For example, +\begin{pygments}{text} +\begin{pyconsole} +var = 1 + 1 +var +\end{pyconsole} +\end{pygments} +yields +\begin{pyconsole} +var = 1 + 1 +var +\end{pyconsole} + + +The \pygment{latex}{\begin} and \pygment{latex}{\end} of an environment should be on lines by themselves. Code in environments may be indented; see the \texttt{gobble} option in the documentation for more details. + +\section*{Macro programming} + +\pytex\ commands can be used inside other commands in macro programming. They will usually work fine, but curly braces should be used as delimiters and special \LaTeX\ characters such as \texttt{\%} and \texttt{\#} should be avoided in the Python code. \pytex\ environments cannot be used inside \LaTeX\ commands, due to the way \LaTeX\ deals with verbatim content and catcodes. + + +\section*{Additional features} + +\pytex\ provides many additional features. The working and output directories can be specified. The user can determine when code is executed with the package option \texttt{rerun}, based on factors such as modification and exit status. By default, all commands and environments run in a single session, providing continuity. Commands and environments accept an optional argument that specifies the session in which the code is executed; sessions run in parallel. \pytex\ provides a utilities class that is always imported into each session. The utilities class provides methods for tracking dependencies and automatically cleaning up created files. + +\pytex\ also provides the \texttt{depythontex} utility, which creates a copy of a document in which all \pytex\ commands and environments have been replaced by their output. The resulting document is more suitable for journal submission, sharing, and conversion to other document formats. + + + +\end{document} |