# Getting listings to highlight Func<x,x,x>

Given this image:

How would you create a lstdefinelanguage that would make Func<double, double, double> highlighted without having to add spaces after each comma?

\documentclass{book}
\usepackage{listings}
\usepackage{color}
\usepackage{xcolor}
\lstdefinelanguage{CSharp}
{
basicstyle=\ttfamily,
keywordstyle=\color{blue!60!black}\bfseries,
morekeywords={double,Func},
alsoletter={[, ]},
}

\lstset{
basicstyle=\footnotesize\ttfamily,
language=[Sharp]C,
alsolanguage=CSharp,
keywordstyle=\color[rgb]{0.0,0,1.0}\bfseries
}
\begin{document}

\begin{lstlisting}
double x = 10;
Func<double> x = 10;
Func<double, double, double> x = 10;
Func<double , double , double> x = 20;
\end{lstlisting}

\end{document}

-
@FilipEkberg: If I remove the addition bracket after morekeywords your example works well. – Marco Daniel Apr 22 '12 at 19:45

Here a simple example that shows an approach.

Based on the given information in the comments you want to highlight combinations like int[]. In this case you shouldn't use alsoletter. Instead use otherkeywords

\documentclass[varwidth,border=10,convert={png,size=800,density=1000}]{standalone}
\usepackage{xcolor}
\usepackage{bera}
\usepackage{listings}
\lstdefinelanguage{mylang}{%
basicstyle=\ttfamily,
keywordstyle=\color{blue!60!black}\bfseries,
morekeywords={double,Func,int},
sensitive=false,
otherkeywords={[, ]}
}
\begin{document}
\begin{lstlisting}[language=mylang]
double x = 10;
Func<double> x = 10;
Func<double, double, double> x = 10;
Func<double , double , double> x = 10;
int[];
\end{lstlisting}
\end{document}


-
Thanks, that works. But it breaks if you add alsoletter={[, ]} If you for instance want to allow int[] to be highlighted too. Is there a reason to that? – Filip Ekberg Apr 22 '12 at 19:46
@FilipEkberg: That has no effect to int. If you set alsoletter={[, ]} you have to define int[] as a keyword. – Marco Daniel Apr 22 '12 at 19:49
@FilipEkberg: I edited my answer. – Marco Daniel Apr 22 '12 at 19:55
Thanks Marco, it broke if I only had the alsoletter-part. But this seem to work very nice. Thanks! – Filip Ekberg Apr 22 '12 at 20:18