There are a number of ways and packages that provide for code listings in LaTeX. One that I personally prefer and that has enough options to customise is the listings package. It provides a multitude of options to pretty print code snippets. It has support for a number of languages which is more along the lines of keywords that is just about enough for code listings.
It has features to
It has features to
- Number the lines
- keyword highlighting
- Ability to add your own keywords
- provide background colour
- whitespace identification for languages that need them
- labeling them for cross reference