# Listings package does not break

The following code does not break even though the breaklines and breakatwhitespace is set:

\lstset{
language=XML,
numbers=left,
numberstyle=\tiny\color{gray},
stepnumber=1,
numbersep=5pt,                  % how far the line-numbers are from the code
backgroundcolor=\color{white},      % choose the background color. You must
showstringspaces=false,         % underline spaces
showtabs=false,                 % show tabs within strings
rulecolor=\color{black},        % if not set, the frame-color
tabsize=2,                      % sets default tabsize to 2 spaces
captionpos=b,                   % sets the caption-position to bottom
breaklines=true,                % sets automatic line breaking
breakatwhitespace=false,        % sets if automatic breaks should only happen
title=\lstname,                   % show the filename of files
% also try caption instead of title
keywordstyle=\color{blue},          % keyword style
breakautoindent=true
% string literal style
}

\lstset{caption={Results of the example},label=lst:results}
\begin{lstlisting}
<message>
</message>
\end{lstlisting}


Any ideas what I can set in order to make it break automatically on the value part?

As described in your question the package listings can automatically break long lines. The is limited. The package breaks only on characters which are defined as others. To allow the break at every point you must say listings that a letter isn't a letter. This can be done be redefining the following definition:

Original:

\def\lst@lettertrue{\let\lst@ifletter\iftrue}


Redefinition

\def\lst@lettertrue{\let\lst@ifletter\iffalse}


The complete code is:

\documentclass{article}
\usepackage[T1]{fontenc}

\usepackage{xcolor}
\usepackage{listings}
\lstset{
breaklines=true,                % sets automatic line breaking
}
\makeatletter
\def\lst@lettertrue{\let\lst@ifletter\iffalse}
\makeatother
\begin{document}

\begin{lstlisting}[caption={Results of the example},label=lst:results,]
<message>

To highlight the automatic line breaks you can work with the options postbreak and prebreak.
• This solution disables the possibility to highlight words by color. Try language=XML, morekeywords={value}, keywordstyle=\color{blue}, with and without \def\lst@lettertrue{\let\lst@ifletter\iffalse}! Any idea how to avoid this clash? – LaRiFaRi Jul 23 '13 at 9:20
• @LaRiFaRi In listings, for an identifier to get highlighted, all of the chars it contains must be "letters". There's no way around that. – jub0bs Aug 10 '14 at 16:04