LaTeX Tips from Practice (3)
April 15, 2009
How to display source code with keyword highlighting and proper comment color
Originally posted at here
Include the package needed with the following line:
\usepackage{listings}
A template of quoting source code with syntax highlighting is as follows:
\usepackage{color}
\usepackage{listings}
\definecolor{Brown}{cmyk}{0,0.81,1,0.60}
\definecolor{OliveGreen}{cmyk}{0.64,0,0.95,0.40}
\definecolor{CadetBlue}{cmyk}{0.62,0.57,0.23,0}
\begin{document}\lstset{language=VBScript,frame=ltrb,framesep=5pt,basicstyle=\normalsize,
keywordstyle=\ttfamily\color{OliveGreen},
morekeywords={one,two,three},
commentstyle=\color{Brown},
stringstyle=\ttfamily,
showstringspaces=ture}\begin{lstlisting}
…
\end{lstlisting}
Adjust accordingly to your preferred language, style and color.
Entry Filed under: All. .
Trackback this post | Subscribe to the comments via RSS Feed