minted vs. texments vs. verbments

Comparison as of March 2013 (see updates below)

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.

Update from July 2016

As of mid-2016, minted will typically be the best option, unless you need specific features in pythontex or one of the other packages.

Since 2013, texments and verbments are unchanged, at least on CTAN. pygmentex has been updated as of May 2015; based on the commit history, there don't appear to have been any major changes.

Since taking over minted development, I have added several major features.

  • Caching. minted performs all highlighting in a single compile, caching highlighted code for future runs. The cache is automatically cleaned as long as the .aux file isn't deleted. The cache can be "frozen" for use in situations in which -shell-escape isn't available (many minted-related things shouldn't be edited in such a situation, since it isn't possible to update the cache).

  • A command for inline code, \mintinline.

  • Unicode support with pdfTeX.

  • Arbitrary escapes to LaTeX using the escapeinside option from Pygments 2.0+ (but note that this can be fragile depending on how Pygments tokenizes).

  • Automatic line breaking at spaces, between all characters, before or after user-specified characters, between space-separated tokens, or between all tokens.

  • bgcolor compatible with page breaks.

I have recently separated most of the line-breaking code, and some additional extensions to fancyvrb, into a new package called fvextra. The next versions of minted and pythontex will both require fvextra; these versions will be on CTAN before the end of July 2016. This will leave minted and pythontex with mostly identical features, although minted will still have the advantage of bgcolor, token-based line breaking, and a few Pygments options in the immediate future. pythontex may still have a speed advantage in some cases, mostly when a lot of highlighted code is modified between compiles, but that should typically be minimal.


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.