# listings bug: space after literate replacement lost with spaceflexible/fullflexible columns

Problem with space being lost in listings immediately after a literate replacement when using columns=spaceflexible or columns=fullflexible (appears correctly with columns=flexible). A small example follows, with problem being that the space after the replaced operator is lost.

Note: This problem is extremely similar to one posted earlier today, but this time, the problem involves the space after a literate replacement, and the space is lost in both \lstinline and lstlisting modes (previous question involved string replacement, and error occurring only in \lstinline mode).

\documentclass{article}
\usepackage{listings}
\lstset{literate=*{{+}{*}{1}}, columns=fullflexible}

\begin{document}

\noindent
\begin{tabular}{ll}
flexible & \lstinline[columns=flexible]!1 + 1!\    spaceflexible & \lstinline[columns=spaceflexible]!1 + 1!\    fullflexible & \lstinline!1 + 1!\    \end{tabular}

\bigskip
\noindent
Within lstlisting environment with columns=flexible
\begin{lstlisting}[columns=flexible]
1 + 1
\end{lstlisting}

\noindent
Within lstlisting environment with columns=spaceflexible
\begin{lstlisting}[columns=spaceflexible]
1 + 1
\end{lstlisting}

\noindent
Within lstlisting environment with columns=fullflexible
\begin{lstlisting}
1 + 1
\end{lstlisting}

\end{document}

-
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 Mar 1 at 19:17

You can use the option keepspaces. For more details have a look at the documentation.

\documentclass{article}
\usepackage{listings}
\lstset{literate=*{+}{*}{1}, columns=fullflexible,keepspaces}

\begin{document}

\noindent
\begin{tabular}{ll}
flexible & \lstinline[columns=flexible]!1 + 1!\    spaceflexible & \lstinline[columns=spaceflexible]!1 + 1!\    fullflexible & \lstinline!1 + 1!\    \end{tabular}

\bigskip
\noindent
Within lstlisting environment with columns=flexible
\begin{lstlisting}[columns=flexible]
1 + 1
\end{lstlisting}

\noindent
Within lstlisting environment with columns=spaceflexible
\begin{lstlisting}[columns=spaceflexible]
1 + 1
\end{lstlisting}

\noindent
Within lstlisting environment with columns=fullflexible
\begin{lstlisting}
1 + 1
\end{lstlisting}

\end{document}

-