Posts Tagged ‘source’

Tango LaTeX Syntax Highlighting

Tuesday, December 9th, 2008

As I have previously mentioned, I am quite a fan of the Tango color palette. In this installment, I want to show how to highlight code listings in LaTeX using the Tango colors like in the following Smalltalk example:

Tango Syntax Highlighting

The screenshot above is actually from a full blown example which I have created for XeLaTeX. If you wish to typeset the example in pdfLaTeX or similar, you can just comment out the lines it complains about.

Let’s go through the source. First of all, you will need the xcolor package to define the custom colors:

\usepackage{xcolor}

Then we can define the colors. I have simply converted the hex color definitions into rgb values acceptable to xcolor. For more information, see the xcolor documentation.

\definecolor{Butter}{rgb}{0.93,0.86,0.25}
\definecolor{Orange}{rgb}{0.96,0.47,0.00}
\definecolor{Chocolate}{rgb}{0.75,0.49,0.07}
\definecolor{Chameleon}{rgb}{0.45,0.82,0.09}
\definecolor{SkyBlue}{rgb}{0.20,0.39,0.64}
\definecolor{Plum}{rgb}{0.46,0.31,0.48}
\definecolor{ScarletRed}{rgb}{0.80,0.00,0.00}

Note that this is just a part of the color definition. See the source for all available colors.

Now that we have defined the Tango colors, we can use them to highlight our source. Depending on the language that you are wishing to highlight, not all numbered keywords will be applicable. I use these different keywordstyles to highlight the above Smalltalk source.

\lstset{
	keywordstyle=[1]{\color{DarkSkyBlue}},
	keywordstyle=[2]{\color{DarkScarletRed}},
	keywordstyle=[3]{\bfseries},
	keywordstyle=[4]{\color{DarkPlum}},
	keywordstyle=[5]{\color{SkyBlue}},
	commentstyle={\color{Aluminium4}},
	stringstyle={\color{Chocolate}},
	basicstyle={\ttfamily},
}

And that’s all you need to use Tango colors for you syntax highlighting in LaTeX. Again, take a look at the source code to see the above code in full.