# Disable keyword highlighting in lstset

I have the following lstset defined for my listings

\lstset{
numbers=left,
numberstyle=\scriptsize,
tabsize=4,
rulecolor=,
language=java,
basicstyle=\scriptsize,
upquote=true,
aboveskip={1.5\baselineskip},
columns=fixed,
showstringspaces=false,
extendedchars=true,
breaklines=true,
prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
frame=single,
showtabs=false,
showspaces=false,
showstringspaces=false,
identifierstyle=\ttfamily,
}


However, the issue is that when I create some java code in a listings, the keywords, such as private, boolean, return etc are hightlighted in bold. I do not want this. Is it possible to disable the bold keyword highlighting?

-
I think adding the key/value parameter keywordstyle=<your keyword style> to your \lstset might help, e.g., keywordstyle=\ttfamily. =) –  Paulo Cereda Aug 25 '11 at 12:25
@Paulo Cereda: why don't you turn your comment into an answer? –  Gonzalo Medina Aug 25 '11 at 12:41
@Gonzalo: I wasn't sure if my suggestion would help the OP. Now that you encouraged me, I expanded my comment to a proper answer. Thanks. –  Paulo Cereda Aug 25 '11 at 12:59
+1: not directly related to your question but your prebreak with ensuremath really helped me. –  Ludovic Kuty Oct 29 '11 at 13:22

There is a key/value parameter named keywordstyle=<value> in which you can redefine the keyword style.

The default settings are: keywords are typeset bold and comments in italic shape. Adding keywordstyle=\ttfamily to \lstset will redefine it:

\documentclass{article}

\usepackage{listings}
\usepackage{upquote}

\lstset{
numbers=left,
numberstyle=\scriptsize,
tabsize=4,
rulecolor=,
language=java,
basicstyle=\scriptsize,
upquote=true,
aboveskip={1.5\baselineskip},
columns=fixed,
showstringspaces=false,
extendedchars=true,
breaklines=true,
prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
frame=single,
showtabs=false,
showspaces=false,
showstringspaces=false,
identifierstyle=\ttfamily,
keywordstyle=\ttfamily
}

\begin{document}

\begin{lstlisting}
public class HelloWorld {

// main method
public static void main(String[] args) {
System.out.println("Hello world");
}
}
\end{lstlisting}

\end{document}


The output:

Hope it helps. =)

-

In addition to Paulo's answer of changing the style of keywords to be identical to the surrounding text, you can also eliminate the set of recognised keywords by adding keywords={} after the language specification.

Code:

\documentclass{article}
\usepackage{listings}
\usepackage{upquote}

\lstset{
numbers=left, numberstyle=\scriptsize,
columns=fixed, frame=single, rulecolor=, aboveskip=1.5\baselineskip,
showspaces=false, showstringspaces=false,
showtabs=false, tabsize=4, extendedchars=true,
breaklines=true, prebreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
language=java,
upquote=true,
basicstyle=\scriptsize, identifierstyle=\ttfamily,
keywords={}
}

\begin{document}

\begin{lstlisting}
public class HelloWorld {
// main method
public static void main(String[] args) {
System.out.println("Hello world");
}
}
\end{lstlisting}
\end{document}


Output:

-
This actually worked better for me than keywordstyle=\ttfamily because with this the keywords were still appearing slightly different (they seemed less bold than the normal code instead), while with keywords={} they were all the same as I required. –  jbx Nov 24 at 23:10
@jbx: Interesting. Thanks for reporting back how it worked. I wouldn't have expected there to still be a difference, especially given the image posted in Paulo's answer. Perhaps the non-keywords are being displayed in a typeface other than just \ttfamily (perhaps in a different size). –  Niel de Beaudrap Nov 25 at 20:33
Yes, the difference is small, but noticable. In my case I didn't have the identifierstyle=\ttfamily though. –  jbx Nov 25 at 23:32