[Tuglist] Package for syntax highlighting

Rajkumar S. tuglist@tug.org.in
Fri, 1 Mar 2002 14:30:12 +0530 (IST)


On Thu, 28 Feb 2002, Radhakrishnan CV wrote:

>      I intend to include C/C++ source code within my document. Is it
>      possible to the syntax of the included source code (such as
>      making the keywords bold etc). Is there a package available for
>      this?
>
>    Please have a look at the "program" package.
>
> Ah, `program' package is painful, you need to recode your source
> files to do the job. Life is miserable if you have thousands of
> lines of code, while lgrind is like riding on a Jaguar, which
> automatically recodes the sources.

Also take a look at listings package

\documentclass[11pt,titlepage,openright]{report}
\usepackage{listings}
\begin{document}
\chapter{Source Code}
\lstset{
  language=C,
  basicstyle=\footnotesize,
  labelstyle=\tiny,%
  labelstep=1
}
\lstinputlisting {malayalam.c}
\end{document}

This will typeset malayalam.c with keyword highlighting and small line
numbers. Just give the path for the source file and all you have to do is
to rerun the latex to get updated dvi when ever you change the source.

Read the manual for more options.

raj