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

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

April 2009
M T W T F S S
« Jun    
 12345
6789101112
13141516171819
20212223242526
27282930  

Most Recent Posts