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

  • 3
    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:

\lstinline{Which spaces     do you mean?}

results in

spaces are preserved

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:

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

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.