Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a LaTeX document with Python code snippets

Tags:

python

latex

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.

like image 817
Escualo Avatar asked Jan 08 '10 19:01

Escualo


1 Answers

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).

like image 99
Noufal Ibrahim Avatar answered Oct 14 '22 20:10

Noufal Ibrahim