# Listings refuses to highlight identifiers such as 'intent–filter'. Why?

I have some xml code, which I want to look fine in my latexdocument. I am doing it this way:

\documentclass[12pt]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[none]{hyphenat}
\usepackage{helvet}
\usepackage{url}
\usepackage{graphicx}
\usepackage[onehalfspacing]{setspace}
\renewcommand{\familydefault}{\sfdefault}
\DeclareGraphicsExtensions{.png}
\usepackage{textcomp}
\usepackage{listings}
\usepackage{color}

\lstset{
basicstyle=\fontsize{12}{12},
columns=fullflexible,
showstringspaces=false,
breaklines=true,
showstringspaces=false,
identifierstyle=\ttfamily,
stringstyle =\color[rgb]{0,0,1}\ttfamily,
keywordstyle=\color[RGB]{49,0,171}\ttfamily,
emph= {action,intent–filter,category, receiver, application, activity, manifest},
emphstyle={\color[RGB]{63,127,127}},alsoletter={-},
}

\begin{document}

\tableofcontents
\newpage

\begin{lstlisting} [language=xml]
<intent-filter>

</intent-filter>
\end{lstlisting}


\end{document}

I am using it for java and xml. It looks fine, but "intent-filter" remains black, the other keywords (I have removed it here) becomes green. Using "intentfilter" works, but it have to be "intent-filter". How can I do that?

• Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – jub0bs May 12 '14 at 13:00
• listings doesn't allow for - in identifiers by default. You must tell it do so explicitly, using alsoletter=-. – jub0bs May 12 '14 at 13:06
• Ok, thank you. I have edited it. I tried it with also letter, but it doesn't have any effect. – Ef Ge May 12 '14 at 13:29
• possible duplicate of How can I get identifier style to apply to '%' (in a Perl listing)? – jub0bs May 23 '14 at 9:39

By default, listings doesn't allow for hyphens - in identifiers. You must tell it do so explicitly, using alsoletter=-. This modification should take place after loading the desired language, because the alsoletter key is (commonly) used in listings' language definitions. Therefore, loading a language too late is likely to overwrite your earlier alsoletter specs.

The following should work:

\begin{lstlisting}[language=xml,alsoletter=-]
<intent-filter><xyz>blablabla</xyz></intent-filter>
\end{lstlisting}


Should but doesn't. Why? Because, in

emph= {action,intent–filter,category, receiver, application, activity, manifest}


the – character is an en-dash character (U+2013), whereas, in your listing, you use hyphens (U+002D). Those two characters only look similar to you, but listings sees them as two distinct characters.

Things get highlighted as expected if you use hyphens throughout.

\documentclass[12pt]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[none]{hyphenat}
\usepackage{helvet}
\usepackage{url}
\usepackage{graphicx}
\usepackage[onehalfspacing]{setspace}
\renewcommand{\familydefault}{\sfdefault}
\DeclareGraphicsExtensions{.png}
\usepackage{textcomp}
\usepackage{listings}
\usepackage{color}

\lstset{
basicstyle=\fontsize{12}{12},
columns=fullflexible,
showstringspaces=false,
breaklines=true,
showstringspaces=false,
identifierstyle=\ttfamily,
stringstyle =\color[rgb]{0,0,1}\ttfamily,