Possible Duplicate:
Syntax Coloring in LaTeX

I'm relatively new to LaTeX, and am starting to use it for academic paper writing. I'm doing a lot of computer programming as part of my academic work, so need to be able to include code extracts easily.

I know I can easily make them appear in a monospaced font, but what would you suggest for getting automatic syntax highlighting?


As the original developer of minted, that’s of course what I recommend.

It uses Pygments to produce beautifully coloured code, e.g.:

On the other hand, I realize that installing minted isn’t trivial, and it relies on an external program. Simpler, more efficient (very noticeable for a large number of code fragments!) and already installed on most systems – but also less versatile than minted – is the package listings. (Furthermore, listings has a nice feature to break over-long lines automatically and indent them correctly. minted can’t do this.)

| improve this answer | |
  • 1
    I have install both minted and pygmentize (v1.2.2), whenever I try to compile a document using minted, I get the following error message : ! Package minted Error: You must have `pygmentize' installed to use this package. However, I can run pygmentize fine from any command prompt. What is going on? – levesque Oct 18 '10 at 18:04
  • @JCL: That’s a bug in the current version. Get the latest version from the trunk of the repository at minted.googlecode.com/hg/minted.sty. Additionally, Windows may make problem. It’s not a supported platform at the moment (since I don’t have it – I can’t troubleshoot Windows problems). – Konrad Rudolph Oct 18 '10 at 18:10
  • After rebooting I got it working, but I don't seem to be able to use Unicode characters, is that normal? – levesque Oct 18 '10 at 18:30
  • @JCL: Only XeTeX really supports Unicode characters. I didn’t get fancyvrb set up properly to support UTF-8 in plain pdfTeX. – Konrad Rudolph Oct 18 '10 at 18:41
  • 1
    The link for minted is broken. You can find it here and here now. – Gustav Bertram Sep 20 '17 at 15:44

Use package listings. But there are other options see: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=codelist.

| improve this answer | |

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