# Adding similar operators to listings

I'm trying to create a new language definition with operators => and >.

Highlighting both => and > doesn't seem to work.

I have tried putting them in otherkeywords in both orders. Neither seem to work.

In the code below, only the > is highlighted. Is it possible to get them both highlighting?

Thanks

\documentclass[a4]{report}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{listings}

\definecolor{backcolour}{RGB}{242,242,0235}
\definecolor{codegray}{RGB}{128,128,128}
\definecolor{codeOrange}{RGB}{254, 97, 0}
\definecolor{codeBlue}{RGB}{100, 143, 255}

\lstdefinestyle{newStyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codeBlue},
keywordstyle=[0]\color{codeBlue},
keywordstyle=[1]\color{codeBlue},
keywordstyle=[2]\color{codeBlue},
keywordstyle=[3]\color{codeBlue},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codeOrange},
basicstyle=\ttfamily,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=4
}

\lstdefinelanguage{newLanguage}{
keywords={type,def,True,False},
otherkeywords={!,\$,|,<,[,],::,=>,>}, otherkeywords={>}, sensitive=true, morecomment=[l]{//}, morecomment=[n]{/*}{*/}, morestring=[b]", morestring=[b]""" } \begin{document} \begin{lstlisting}[language=newLanguage,style=newStyle] a = [1,>,2] b => c \end{lstlisting} \end{document}  ## 1 Answer Support for the otherkeywords option is "a bit buggy" at the moment if the same character occurs in different keywords (see also this question). You can check the behavior for different keyword lists: otherkeywords={!,\$,|,<,[,],::,>}


otherkeywords={!,\$,|,<,[,],::,=>}  Those are correct. But as soon as you add both, things go wrong: otherkeywords={!,\$,|,<,[,],::,=>,>}


As a workaround you could use the literate option to set the style for all literate occurrences of => explicitly:

otherkeywords={!,\\$,|,<,[,],::,>},
literate={=>}{{\textcolor{codeBlue}{=}}{\textcolor{codeBlue}{>}}}{2}


The drawback of this approach is that => will be replaced in all places, so operators like ==> will be apprear incorrect.