TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Regarding the typesetting of syntax-colored source code, I know that listings is inferior because it doesn't utilize a full lexer. Instead the Python-based solution is recommended. It seems there are three packages to use the Python library pygments instead: minted, texments and verbments.

Most people seem to use minted here. The verbments documentation says it aims to fix issues with minted.

So what are the important differences? Has someone tried all of them?

share|improve this question
up vote 50 down vote accepted

I'm somewhat familiar with all the common packages that use Pygments. As part of writing my pythontex package, I researched what had been done previously.

  • texments is pretty basic. It doesn't provide access to much of Pygments or fancyvrb's functionality.
  • minted provides much more complete access to Pygments and fancyvrb, and adds additional functionality like background colors.
  • verbments is more recent than minted, which probably explains why it is apparently less popular. The verbments documentation says that "the minted package cannot split the highlighted source code over pages." Technically, minted can do that fine--the problem is with the listing float that minted provides. (Edit: There are also page break issues when a background color is used, but those can be overcome by not using the package's bgcolor option and using mdframed or a similar package instead.) The verbments solution is to allow listing numbering and captions--but without providing a real float (which would have to solve the page break problem). verbments also provides individual highlighting styles (you can use different Pygments styles for each environment) and a few additional options that minted lacks.
  • pygmentex is yet another Pygments package (2012-02-12). It includes custom patches for Pygments to allow escaping to LaTeX anywhere. That is nice, but may also make maintenance difficult as Pygments continues to develop. (That feature has been requested in Pygments since early 2010, and is still open.) pygmentex provides an inline command. And it caches output.

  • And finally, there's my pythontex package. (First release 2012/04/27, but in development for the previous year.) Its main purpose is to allow Python code to be included in a LaTeX document, with a means to execute the code and bring back the output. Adding Pygments highlighting was actually something of an afterthought. pythontex provides most of minted's functionality, except for a few things like background colors (since these can be so easily added with packages like mdframed). It caches all highlighted content, using the mechanism I'd already created for caching the output of executed code. It also provides an inline command, allows automatic line number continuation between environments of the same language, and allows fancyvrb settings on a per-language basis. Unicode is supported with the pdfTeX engine.

So this leaves us with many options for Pygments highlighting. Caching is really important for performance, but the downside is that both my approach and the pygmentex approach require compiling (which saves code to an auxiliary file), running a Python script (which uses Pygments to do the highlighting, then saves the output), and compiling a second time (which brings back the highlighted output). One of the really nice things about the \write18 approach used by the other packages is that the highlighting is always up-to-date and only requires a single compile. It probably wouldn't be hard to cache and keep everything up-to-date using LuaTeX. Otherwise, I would think about \pdfmdfivesum (possibly with temp files), except that I don't believe XeTeX has an equivalent. There may not be a good cross-engine alternative to the three-step process.

pythontex is under active development and should continue to provide Pygments highlighting for the foreseable future. While the focus is access to Python, I'm in the midst of a major refactoring that should allow the package to be extended for arbitrary languages, with only a few dozen lines of code needed per extension. The disadvantage of all this is that pythontex isn't quite as nimble as a highlighting-only package.

Edit: After corresponding with Konrad Rudolph, I have decided to maintain minted. Development will be at https://github.com/gpoore/minted.

share|improve this answer
In my recent feynmp-auto package I used \pdfmdfivesum for avoiding running Metapost if the file didn't change. You can have a look at how it's done; however XeLaTeX hasn't the feature. – egreg Mar 20 '13 at 17:32
minted v2.0 adds caching capability as well as inline highlighting. – Adobe Mar 31 '15 at 13:00

Current status: minted maintenance has been handed over to Geoffrey Poore.

minted is essentially unmaintained at this point. I tried fixing as many bugs as possible but two things are getting in the way:

  1. I don’t have time for side-projects any more. This is unfortunate. In fact, I developed minted mainly for my own master thesis and ended up not using it there due to the fact that some tedious things remained unfixed.
  2. Many interesting changes, among them the two most important ones (inline code highlighting, performance improvement via caching and change tracking) would ideally require changes in the upstream Pygments code base, and so far these changes (which have been submitted as patches to Pygments) have not been integrated.

I don’t know how (if) verbments works around this limitation – maybe they are maintaining their own branch of the Pygments project and don’t care for compatibility, or they’re performing some interesting parsing work in LaTeX itself. Either way I applaud the effort. I’d have preferred it if they had built on top of minted (to avoid duplicating work and having several projects doing the same thing) but then I also started my own package instead of building on top of texments so I understand the motivation behind this.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.