I have the following:


It is (correctly) showing code in black, with keywords in blue. However, I would like all inline code to appear in a distinct color (browny/reddish). How can I achieve this?

Note that I can not redefine \code to look something like this:


This is because of this issue, wherein I have inline code snippets that includes backslashes. I started pursuing a solution that uses \color, but I couldn't figure out how to do that given the above constraint.

  • 1
    Maybe you could use optional parameter for \lstinline to redefine colors for keywords and other symbols: \newcommand*{\code}{\lstinline[keywordstyle=\color{brown}, basicstyle=\color{brown}]} – Ignasi Jan 25 '18 at 11:33
  • @Ignasi excellent - that worked! Happy to accept as answer if you add one. – Kent Boogaart Jan 25 '18 at 23:37

You can always add a particular listing style into the optional argument of lstinline:

\newcommand*{\code}{\lstinline[keywordstyle=\color{brown}, basicstyle=\color{brown}]}

In this case, you'll have to define another command when you need other listing settings.


\newcommand*{\code}{\lstinline[keywordstyle=\color{brown}, basicstyle=\color{brown}]}

\newcommand*{\codered}{\lstinline[keywordstyle=\color{red}, basicstyle=\color{green}]}



\lstinline{for (i=0; i<5; i++) if (i==0)}

\code{for (i=0; i<5; i++) if (i==0)}

\codered{for (i=0; i<5; i++) if (i==0)}


enter image description here

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.