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?

2 Answers 2


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.

  • 3
    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
    Commented Mar 20, 2013 at 17:32
  • 1
    minted v2.0 adds caching capability as well as inline highlighting.
    – Adobe
    Commented Mar 31, 2015 at 13:00
  • 1
    Since the answer were given some years have passed. How does it look today? Is minted still preferable? Especially the escape from pygments to LaTeX (as proposed for pygmentex) is of interest to me. Should I start a bounty, open new question? Thanks for the review.
    – math
    Commented Jul 6, 2016 at 6:39
  • 5
    @math I've added an update for July 2016.
    – G. Poore
    Commented Jul 8, 2016 at 23:44
  • Any alternative to minted? Minted lacks of captions and some important things. In order to have it you need to write quite a lot of code.
    – skan
    Commented Sep 11, 2019 at 11:29

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .