# lstlistings works strangely

I have some Java source code and want to display it in LaTex:

\lstset{language=Java}
\begin{lstlisting}
IntentFileter intentfilter = new IntentFilter();
g = new blm(this, null);
\end{lstlisting}


But the output is indeed ugly:

Did I do something wrong or this is what it ought to be?

-

This may serve to be a starting point towards procrastination and beautification:

\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}

\lstset{language=Java,
basicstyle=\footnotesize\ttfamily,
stringstyle=\ttfamily,
showstringspaces=false,
breaklines=true,
frameround=ffff,
frame=single,
rulecolor=\color{black},
tabsize=1,
keywordstyle=\color{red}\bfseries,
columns=fullflexible,
morekeywords={public, class}
}

\begin{document}
\begin{lstlisting}
IntentFileter intentfilter = new IntentFilter();
g = new blm(this, null);
\end{lstlisting}
\end{document}


You can customise further using the directives inside \lstset. For details, refer to listings manual. For extreme beautification, you may use tcolobox with its listings only option. Search for tcblisting in tcolorbox documentation.

-
Your enthusiasm did impress me. And I'm still wondering why there isn't a more convenient way to have a better format of source code, at least a monospace font for example. – Elderry Mar 7 '14 at 9:01
@Elderry Not choosing a monospace font by default was a precise choice made by the package author, who was apparently fond of listings in normal type. I usually add also columns=fullflexible to avoid spaced letters. – egreg Mar 7 '14 at 9:56
Instead of keywordstyle=\color{red}\bf, you could put keywordstyle=\color{red}\bfseries, to get bold monospaced letters if available (unless you DID want that output). – Manuel Mar 7 '14 at 10:07
@egreg Thanks. I left many things assuming that the list may grow. I added it now. :) – Harish Kumar Mar 7 '14 at 10:11
@Manuel That was a nice suggestion and I did bad copy pasting. Corrected. :) – Harish Kumar Mar 7 '14 at 10:11