# Preserving white spaces in inline listings

Is there any way of preserving white spaces in \lstinlne{}?

• Usually they are preserved, so please add a MWE, that shows the problem. – Schweinebacke Mar 7 '17 at 13:58

Preserving spaces it the usual behavior of \lstinline, so you have nothing else to do but not changing the default behavior:

\documentclass{article}
\usepackage{listings}
\begin{document}
\lstinline{Which spaces     do you mean?}
\end{document}


results in

Note: You should not use \lstinline inside the arguments of other commands, because the tokens are already build by reading the argument of the topmost command. See the listings manual, section 6.1 for more information about using listings inside the argument of another command.

However, color for inline listings can be done, e.g., using:

\documentclass{article}
\usepackage{xcolor,listings}
\begin{document}
\lstinline{Which spaces     do you mean?}

Colors in inline listings do work with:
\lstinline[basicstyle=\ttfamily\color{red}]|red listing   with spaces|
or {\color{red}\lstinline|red listing   with spaces|}.
\end{document}

• The problem was that I used it inside text color: \textcolor{red}{\lstinline{aaa bbb}} – Mihai Nov 16 '17 at 7:54
• @Mihai Now you should know, why you always should add a minimal but working example to your questions! Please add one to your question as asked 25 minutes after you have posted the question month ago! – Schweinebacke Nov 16 '17 at 9:38