15

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

enter image description here

\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}
18

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

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.