# Why is lstlisting splitting my XML tags?

I have a little problem with this ambient. I have some XML to insert into my document and the thing that really bugs me is that the new line breaks a closing tag in two. I indicated to the environment that I am using XML but to no use. This is the code:

\begin{lstlisting}[language=XML]
<ce:bib-reference id="BIB14">
<ce:label>[14]</ce:label>
<ce:other-ref>
<ce:textref>W. Mitchell, How weak is the closed, unbounded filter?, Preprint.</ce:textref>
</ce:other-ref>
</ce:bib-reference>
\end{lstlisting}


The tag </ce:textref> is split into </ on the first line and ce:textref> on the second. This is my preamble:

\documentclass[10pt,a4paper,titlepage,twoside,openright]{book}
\usepackage{listings}
\lstset{basicstyle=\footnotesize\ttfamily,breaklines=true,escapeinside={~*}{*~}}


Here is a screenshot of the output:

• 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 Feb 24 '14 at 10:23
• Ariel, your should post your code in one piece; don't break it apart (preamble here, body there) because people who want to test it have to (tediously) piece it back together. Besides, I can't reproduce the problematic line break you report. Could you post or link to a screenshot of the output? – jub0bs Feb 24 '14 at 12:46
• Please complete your code. We still don't know which document class you're using. If I simply use article, I don't get the problematic line break you mentioned. – jub0bs Feb 24 '14 at 13:39
• I still can't reproduce the problem. Have you tried updating your TeX distribution? – jub0bs Feb 24 '14 at 14:08
• I am using www.sharelatex.com – Ariel Feb 24 '14 at 14:11

use option breakatwhitespace
\lstset{basicstyle=\footnotesize\ttfamily,breaklines,

• I suspect that the OP already uses breaklines in the preamble because he reports a line break in the output, and listings doesn't effect any line break unless option breaklines is set. – jub0bs Feb 24 '14 at 11:46
• I think the breakatwhitespace option is just what I was looking for. Many thanks! – Ariel Feb 24 '14 at 14:45