Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
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

2 Answers

up vote 6 down vote accepted

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:

Hello world

Hope it helps. =)

share|improve this answer

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:

Code listing with keywords set to null

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.