[SciPy-user] embedding Python code in LaTeX

Ryan Krauss ryanlists at gmail.com
Tue Jan 17 08:21:29 CST 2006


Thanks to everyone who replied.  All three of these are good
solutions.  The listings package seems pretty flexible as is giving me
nice looking results without too much effort with Fernando's and
Prabhu's customization suggestions.

Ryan

On 1/17/06, Arnd Baecker <arnd.baecker at web.de> wrote:
> Hi,
>
> 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:
> \usepackage{fancyvrb}
>
> % include a .py file
> \VerbatimInput[frame=lines,fontshape=sl,fontsize=\footnotesize]{spanish.py}
>
> Documentation:
> http://www.tug.org/tetex/tetex-texmfdist/doc/latex/fancyvrb/fancyvrb.ps
>
> 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
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user
>



More information about the SciPy-user mailing list