[Matrix-SIG] Running python from latex

Pearu Peterson pearu@ioc.ee
Mon, 17 May 1999 19:37:02 +0300 (EETDST)


Hi!

I wrote a LaTeX package runpython.sty. Using this one can run Python code
from LaTeX, display the code and also the results in latex verbatim
environment. So, it can be useful in writing documentation
and examples for python codes.

You can download runpython.sty and see examples in
  http://koer.ioc.ee/~pearu/python/
Below is an example LaTeX document.

Best regards,
	Pearu

\documentclass[12pt,a4paper]{article}
\usepackage{runpython}
\begin{document}
Let us print out some members of Fibonacci series. Here is how you can
find them  in python. First we initialize
\begin{python}
a, b = 0, 1  
\end{python}
and then iterate
\begin{python}
while b < 10:
    print b,
    a, b = b, a+b
\end{python}
Here are the results:
\runpython

Another example (also taken from Python Tutorial):
\begin{python}
def f(x): 
    return x % 2 != 0 and x % 3 != 0
print filter(f, range(2, 25))
\end{python}
Here is the result
\runpython
\end{document}