A gentle introduction to

نویسندگان

  • Andrew Mertz
  • William Slough
چکیده

The PythonTEX package allows authors to combine computational and typesetting tasks by embedding Python code in TEX documents. This package allows access to many powerful Python modules, providing support for such things as symbolic mathematics, plotting, arbitrary precision numerical calculations, and networking. Python’s intuitive syntax, popularity, and extensibility along with TEX’s formatting strengths make them a logical combination for programming documents. By examining a variety of examples, we will provide an overview of the capabilities and possibilities of PythonTEX. 1 Motivation and overview As widely appreciated by its users, TEX is a typesetting system with numerous strengths and capabilities, providing the ability to create beautiful documents. Although it provides a capability for the definition of macros, designing and implementing them can be a daunting experience, especially for non-experts. Python [9] is a programming language which has attracted a large number of users. As a further enhancement, scientific and technical computing is supported by an extensive collection of modules and utilities. These provide capabilities for numerical integration, linear algebra, linear programming, sparse matrix manipulation, symbolic mathematics, and plotting, for example. PythonTEX [8] allows authors to combine the computational power of Python with the typesetting capabilities of TEX. This marriage of computational and typesetting worlds yields some exciting possibilities, as we intend to show in this paper. Using the PythonTEX package, Python code may be placed directly into a LTEX document. During processing of this document — and “behind the scenes” — wherever Python code appears, a Python interpreter is executed, producing results which are then injected into the document in place of that code. PythonTEX provides a variety of macros and environments with various optional arguments. It also has a tool, depythontex, for creating merged documents consisting of the original LTEX source and the Python output. This resulting document can then be processed without PythonTEX. Our aim is to provide an introduction, so we limit ourselves to a small, yet powerful, subset of PythonTEX. 2 Getting started To begin, some installation will probably be needed. The PythonTEX package can be found at CTAN and installed, for example, by use of a package manager such as TEX Live’s tlmgr. In addition, a Python installation is needed, with Python 2.7 being the recommended version. The exact details of how this is done depend on your system, but one relatively simple way to obtain it is to download and install Anaconda [1]. (We are grateful to Richard Koch, from whom we learned about this resource.) Anaconda is a free Python distribution which supports GNU/Linux, Windows, and Mac OS X. Not surprisingly, a document to be processed with PythonTEX will need to indicate this in its preamble: \usepackage{pythontex} A number of optional arguments can be supplied, though none of these are needed for what is being described in this introduction. For full details, refer the PythonTEX documentation. Three steps are needed to process a PythonTEX document: first, LTEX, then PythonTEX, and finally LTEX. (Various engines are possible, including pdfLTEX, LuaLTEX, and X E LTEX.) For example, the document sample.tex could be processed with the following sequence of commands. pdflatex -interaction nonstopmode \ -draftmode sample.tex pythontex sample.tex pdflatex sample.tex The first step extracts the Python code from the document (to the file sample.pytxcode). In the second step, this code is given to the Python interpreter and the results are saved to a variety of files within the subdirectory pythontex-files-sample. In the final step, the results from Python are merged with the original document. 3 Fundamental PythonTEX We begin our exploration by considering two macro commands intended for inline code: \py and \pyc. To use \py, a single-line Python expression is supplied as an argument:

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

A Gentle Introduction to Yao’s Garbled Circuits

This is a short, gentle introduction to the Yao’s Garbled Circuits construction and recent optimizations, as well as the garbled circuit definitions.

متن کامل

Slicing Planar Grid Diagrams: a Gentle Introduction to Bordered Heegaard Floer Homology

We describe some of the algebra underlying the decomposition of planar grid diagrams. This provides a useful toy model for an extension of Heegaard Floer homology to 3-manifolds with parametrized boundary. This paper is meant to serve as a gentle introduction to the subject, and does not itself have immediate topological applications.

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2013