Syntax highlighting in LaTeX

2010-12-26

I just discovered the minted LaTeX package to highlight source code. Perfect! I never like the listings package.

Minted has been developed by Konrad Rudolph. It relies on Pygments which is easily installed using e.g.,

$ sudo easy_install Pygments
$ cat > 1.py
import numpy
print numpy.version
^D
$ pygmentize -f html -O full -o 1.html 1.py

Here is a short example of rendering R and Python code:

The source file is here: test_minted.tex. To compile, just run

$ xelatex -shell-escape test_minted.tex

What I like is:

  • Its syntax looks like that for the listings package, so it’s easier to switch to it.
  • It has good unicode support.
  • It offer full-support for R, and more esoteric language that I like (e.g., Asymptote), but try pygmentize -L lexers at the shell prompt.

I seem to remember having tried the highlight program, but I cannot find any trace of it on my old computer.

---

Articles with the same tag(s):

From Beamer to Deckset
Weaving Stata documents
Easier literate programming with R
Happy texying
Weaving scientific document
Asymptote and Metapost
Switching to biblatex
Upgrading CONTEXT

---