[SciPy-user] embedding Python code in LaTeX

Arnd Baecker arnd.baecker at web.de
Tue Jan 17 01:18:35 CST 2006


On Tue, 17 Jan 2006, Prabhu Ramachandran wrote:

> >>>>> "Fernando" == Fernando Perez <Fernando.Perez at colorado.edu> writes:
>     Fernando> 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.
>     Fernando> The listings latex package, combined with this, gives me
>     Fernando> results I'm quite happy with (colors optimized so they
>     Fernando> read well on print, even if a b/w printer is used):
>     Fernando> \usepackage{listings} \lstset{
> Yes, I strongly recommend listings as well, fwiw, this is what I use:
> \usepackage{listings}
> \lstset{language=Python,
>   commentstyle=\color{red}\itshape,
>   stringstyle=\color{darkgreen},
>   showstringspaces=false,
>   keywordstyle=\color{blue}\bfseries}

I usually use fancyvrb:

% include a .py file


Interestingly, the listings package has an interface to fancyvrb
(sec 4.15. in the manual of listings v1.2).
As fancyvrb does not do pretty printing,
the combination of listings and fancyvrb might give you maximum
flexibility ...

Best, Arnd

More information about the SciPy-user mailing list