I'm writing a thesis where I need to highlight XML, C# and Python code, here is my definition, but all I get is the same highlight for all three types.
\documentclass[a4paper,slovak,12pt]{article}
% Packages
\usepackage{epsf}
\usepackage{epsfig}
\usepackage{latexsym}
\usepackage[T1]{fontenc}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{ucs}
%\usepackage[utf8x]{inputenc} Nejde dobre s listings package
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage[usenames]{color}
\usepackage{newcent}
\usepackage[slovak]{babel}
\usepackage[bottom]{footmisc}
\usepackage{changepage}
\usepackage{graphicx}
\usepackage{setspace}
\onehalfspacing
\usepackage[numbers]{natbib}
\usepackage{natbib}
\usepackage{lmodern}
\usepackage[top=2.5cm,left=3.5cm,right=2cm,bottom=2.5cm]{geometry}
\usepackage{booktabs}
\usepackage{hhline}
\usepackage{setspace}
\usepackage{url}
\usepackage{eso-pic}
\usepackage{listings}
\usepackage{times}
\usepackage{eurosym}
\usepackage{perpage}
\usepackage{footmisc}
% \usepackage[none]{hyphenat}
\makeatletter\chardef\l@nohyphenation=255 \makeatother
\usepackage[slovak=nohyphenation,czech=nohyphenation]{hyphsubst}
\sloppy
\usepackage{listings}
\usepackage{color}
\usepackage{soulutf8}
\usepackage{filecontents}
\usepackage{array}
\newcommand{\thickhline}{%
\noalign {\ifnum 0=`}\fi \hrule height 2pt
\futurelet \reserved
}
\newcolumntype{H}{@{\hskip\tabcolsep\vrule width 2pt}}
% Colors
\definecolor{gray}{rgb}{0.35,0.35,0.35}
\definecolor{blue}{rgb}{0,0,1}
\definecolor{red}{rgb}{1,0,0}
\definecolor{green}{rgb}{0,1,0}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\definecolor{cyan}{rgb}{0.0,0.6,0.6}
\definecolor{yellow}{rgb}{1.0,1.0,0.0}
\definecolor{orange}{rgb}{0.44, 0.44, 0.0}
\lstset{
language=XML,
basicstyle=\ttfamily,
columns=fullflexible,
showstringspaces=false,
commentstyle=\color{gray}\upshape,
inputencoding=utf8,
extendedchars=true,
literate=%
{á}{{\'a}}1
{ä}{{\¨{a}}}1
{č}{{\v{c}}}1
{ď}{{\v{d}}}1
{é}{{\'e}}1
{ě}{{\v{e}}}1
{í}{{\'i}}1
{ň}{{\v{n}}}1
{ó}{{\'o}}1
{ô}{{\^{o}}}1
{ř}{{\v{r}}}1
{š}{{\v{s}}}1
{ť}{{\v{t}}}1
{ú}{{\'u}}1
{ů}{{\r{u}}}1
{ý}{{\'y}}1
{ž}{{\v{z}}}1
{Á}{{\'A}}1
{Č}{{\v{C}}}1
{Ď}{{\v{D}}}1
{É}{{\'E}}1
{Ě}{{\v{E}}}1
{Í}{{\'I}}1
{Ň}{{\v{N}}}1
{Ó}{{\'O}}1
{Ř}{{\v{R}}}1
{Š}{{\v{S}}}1
{Ť}{{\v{T}}}1
{Ú}{{\'U}}1
{Ů}{{\r{U}}}1
{Ý}{{\'Y}}1
{Ž}{{\v{Z}}}1
}
\lstdefinelanguage{XML}
{
morestring=[b]",
morestring=[s]{>}{<},
morecomment=[s]{<?}{?>},
stringstyle=\color{black},
identifierstyle=\color{darkblue},
keywordstyle=\color{cyan},
morekeywords={xmlns,version,type}% list your attributes here
}
\newenvironment{indentVariation}[1]%
{\begin{list}{}%
{\setlength{\leftmargin}{#1}}%
\item[]%
}
{\end{list}}
% Listings
\lstdefinestyle{color}
{identifierstyle=\color{green}\bfseries, commentstyle=\color{yellow}\bfseries, stringstyle=\color{blue}, keywordstyle=\color{red}\bfseries,morecomment=[l]{\#}}
\lstset{breakindent=13pt,breaklines=true,inputencoding=utf8,tabsize=2,showtabs=false,tab=$\to$,style=color,basicstyle=\footnotesize\ttfamily\bfseries,frame=lines,frameround=tttt}
\renewcommand{\labelitemi}{$\vcenter{\hbox{\small$\circ$}}$}
\lstset{
language=Python,
showstringspaces=false,
formfeed=\newpage,
tabsize=4,
commentstyle=\itshape,
basicstyle=\ttfamily,
morekeywords={models, lambda, forms}
}
\lstdefinelanguage{CSharp}
{
sensitive=true,
morekeywords=[1]{
abstract, as, base, break, case,
catch, checked, class, const, continue,
default, delegate, do, else, enum,
event, explicit, extern, false,
finally, fixed, for, foreach, goto, if,
implicit, in, interface, internal, is,
lock, namespace, new, null, operator,
out, override, params, private,
protected, public, readonly, ref,
return, sealed, sizeof, stackalloc,
static, struct, switch, this, throw,
true, try, typeof, unchecked, unsafe,
using, virtual, volatile, while, bool,
byte, char, decimal, double, float,
int, lock, object, sbyte, short, string,
uint, ulong, ushort, void},
morecomment=[l]{//},
morecomment=[s]{/*}{*/},
morecomment=[l][keywordstyle4]{\#},
morestring=[b]",
morestring=[b]',
}
.texfile? Then I can paste the whole thing into my editor and reproduce the problem you described. – John Wickerson May 13 '13 at 09:23\lstdefinestyle{mystyle}{...}\lstnewenvironment{mycode}{\lstset{style=mystyle}}{}– cgnieder May 13 '13 at 11:30