Take the 2-minute tour ×
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.

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?

share|improve this question

marked as duplicate by Joseph Wright Dec 6 '11 at 8:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

up vote 28 down vote accepted

As the 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.)

share|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

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

share|improve this answer

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