[SciPy-user] embedding Python code in LaTeX

Fernando Perez Fernando.Perez at colorado.edu
Mon Jan 16 22:23:51 CST 2006


Ryan Krauss wrote:
> Can anyone recommend a good way to embed python code in a LaTeX
> document?  Preferably a LaTeX package or Python module that converts
> code to LaTeX.  I would like to have the code snippets look pretty in
> my thesis.

The listings latex package, combined with this, gives me results I'm quite 
happy with (colors optimized so they read well on print, even if a b/w printer 
is used):

\usepackage{color}

\definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
% Use and configure listings package for nicely formatted code
\usepackage{listings}
\lstset{
   language=Python,
   basicstyle=\small\ttfamily,
   commentstyle=\ttfamily\color{blue},
   stringstyle=\ttfamily\color{orange},
   showstringspaces=false,
   breaklines=true,
   postbreak = \space\dots
}


hth,

f



More information about the SciPy-user mailing list