[Tex/LaTex] Eat space in a line break in \lstinline{}

formattinglistings

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.

Best Answer

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}.

Related Question