# Eat space in a line break in \lstinline{}

I use the listings package. If a line break inside a multi-word \lstinline{} occurs, I get a nasty spaces at the beginning of the new line:

page left                  page right
|                          |
|normal text normal text IF|
| FORALL normal text       |


IF FORALL is inside a \lstinline{}.

How to avoid the space before FORALL?

Thanks!

EDIT: I don't mind to elaborate. I am typing a document that includes some inline code snippets. I use \lstinline{} to typeset them (since I also use lstlisting in my document).

The illustration above depicts the result from latex code:

normal text normal text \lstinline{IF FORALL} normal text


Now if IF FORALL does fit into a single line, I get

    |normal text normal text IF FORALL normal|
|text                                    |


on my page, which is fine. The | mark the start of the page margin.

If IF FORALL is broken down into multiple lines, I get the result shown above. I would much rather like to have:

    |normal text normal text IF|
|FORALL normal text        |


Hope that this makes it more clear. Thanks.

-
Start by posting a minimal example of what you are doing. –  Joseph Wright Sep 30 '10 at 20:32
Let me know if this makes it more clear –  Frank Seifert Oct 5 '10 at 12:41
This is a lot better. –  Caramdir Oct 5 '10 at 14:27
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Feb 27 '14 at 11:33

The space is the one between the IF and the FORALL. I don't know if it is possible to eat it somehow, but you can at least move a bit back:

\documentclass{book}
\usepackage{listings}
\lstset{breaklines,postbreak=\kern-1ex}
\textwidth=4cm
\parindent=0cm
\begin{document}
normal text normal text \lstinline{IF FORALL} normal text
\end{document}


Addition: I just realized, that the space disappears too if you use \lstset{breaklines,breakatwhitespace}

Addition 2: An obvious solution which avoids all this hassle with the white space is to use two \lstinline commands: \lstinline{IF} \lstinline{FORALL}.

-
@Ulrike: Your first solution doesn't work: -1ex isn't quite correct, but that's not the main problem. If you increase the text width to 4.3cm, then "IF " fits on the first line, and the second line starts with "FORALL", moved to the left by -1ex. That's definitely not desired. Your second solutions seems to work perfectly, at least with a recent TeX installation! So could you please replace your first solution with the second one? –  Hendrik Vogt Oct 22 '10 at 14:13
Well no: the second doesn't work perfectly either, as then (with textwidth=4.3cm) the first line is a bit to short (the space behind the IF is there). The perfect solution is postbreak=\kern-1ex when the break is before the space and prebreak=\kern-1ex if the break is after the space. –  Ulrike Fischer Oct 22 '10 at 15:18
Oh my, you're right, the breakatwhitespace option doesn't solve the problem either. To me this seems like a bug in the package. Anyway, this breakatwhitespace isn't well documented. Still your \kern-1ex isn't perfect, but it's not clear how to make it better: It seems that the width of the white space varies depending on the letters around it. So at the moment, your "Addition 2" seems like the best solution. –  Hendrik Vogt Oct 22 '10 at 17:26

This doesn't answer your question per se, but what I do is either rewrite the text so that the listing fits on a single line, or if that is not possible for whatever reason, then make it a nonfloating listing. This takes a little extra space, but I think it is more readable than having it break.

-

This is apparently not implemented at this time.

-