8

I am using LaTeX to write a document about Python. This document will contain code snippets (examples).

I could use the verbatim environment, but before I embark onto it, I'd like to know if you are aware of any LaTeX style file which provides an environment for Python code. Syntax highlight would be a plus.

Thanks.

Edit:

I must point out that the package minted is exactly what I was looking for. It has beautiful syntax highlighting and it is very simple to use. Check this question to know more about it.

Community
  • 1
  • 1
Escualo
  • 40,844
  • 23
  • 87
  • 135

3 Answers3

5

Take a look at this question Source code highlighting in LaTeX for more information.

You should also look at the pygments program for source code highlighting.

I personally use Emacs org-mode with #+BEGIN_SRC python and let htmlize.el take care of the highlighting during export. You can see a sample here (This is an HTML export but with the latest version of org-mode, it can use the listings LaTeX package to colourise exported PDFs too).

Community
  • 1
  • 1
Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169
  • 1
    Thank you. I am sorry about having repeated the question unknowingly. The package minted is the solution I was looking for. – Escualo Jan 08 '10 at 20:48
2

Use Docutils and RST for this. It has Latex with Syntax highlighting.

http://docutils.sourceforge.net/docs/user/latex.html

S.Lott
  • 384,516
  • 81
  • 508
  • 779
2

The LaTeX Listings package seems to know about Python. Worth taking a look at.

Mark

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161