One way to do achieve this would be to define otherkeywords
for these cases.
otherkeywords={attribute=, xmlns=}
Code:
\documentclass[a4paper, 12pt]{article}
\usepackage{listings, color}
\definecolor{forestgreen}{RGB}{34,139,34}
\definecolor{orangered}{RGB}{239,134,64}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\definecolor{gray}{rgb}{0.4,0.4,0.4}
\lstdefinestyle{XML} {
language=XML,
extendedchars=true,
breaklines=true,
breakatwhitespace=true,
emph={},
emphstyle=\color{red},
basicstyle=\ttfamily,
columns=fullflexible,
commentstyle=\color{gray}\upshape,
morestring=[b]",
morecomment=[s]{<?}{?>},
morecomment=[s][\color{forestgreen}]{<!--}{-->},
keywordstyle=\color{orangered},
stringstyle=\ttfamily\color{black}\normalfont,
tagstyle=\color{darkblue}\bf,
morekeywords={attribute,xmlns,version,type,release},
otherkeywords={attribute=, xmlns=},
}
\begin{document}
\begin{lstlisting}[style=XML]
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<note attribute="main" xmlns="http://www.w3.org/1999/xhtml">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Dont forget me this weekend!</body>
</note>
\end{lstlisting}
\end{document}
It is always good to post a minimal and compilable example, not just code snippets. This way, the answerers do not have to guess what's happening with your problem.
I guess that you are looking for something like this.
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\lstset{language=Python,
morekeywords={as,__init__,MyClass},
keywordstyle=\color{teal}\bfseries,
}
\begin{document}
\lstinputlisting{guess.py}
\end{document}
where guess.py
is your sample code snippet. I just added as on the last line to show that morekeywords
works.
class MyClass(Yourclass):
def __init__(self, myvar, yours):
bla bla bla... as
Here is the output.
You can also remove __init__
from morekeywords
option and use the answers in How to I emphazise all words beginning with ` in an lstlisting and Listings language definition keyword suffixes. So you may put the following code snippet into your preamble.
\lstset{language=Python,
morekeywords={as,MyClass},
keywordstyle=\color{teal}\bfseries,
keywordsprefix=_,
}
Let me know if this works for you.
Best Answer
Open TeXmaker File menu --> Options-->Configure-->Editor--> Colors and change according to your liking based on color codes. Just for update: TeXmaker 4.0.1 dated March 16 2013 is available now