# Can you change lstinline without changing the global lstset?

Consider that I want to be able to write:

\inline{some code or keyword} and just have it distinguished from the rest of the paragraph text, I've done that like this:

\def\inline{\lstinline[basicstyle=\ttfamily]}


However, if you have a custom \lstset that sets for instance keywordstyle, this will be used for the inlining as well! Is there a way to remove that? Is it possible to use something like \lstnewenvironment to accomplish it?

-

## 2 Answers

You can override keywordstyle on a case-by-case basis in \lstinline:

\documentclass{article}
\usepackage{listings,xcolor}
\lstset{keywordstyle=\sffamily\color{red},language=C}
\def\inline{\lstinline[basicstyle=\ttfamily,keywordstyle={}]}

\begin{document}
Compare \lstinline|int a=3;| with red sans-serif keywords to
\inline{int a=3;} where keywords inherit from basicstyle.
\end{document}


-
Very nice! How about if you have more keywordstyles, this wont work: \def\inline{\lstinline[basicstyle=\ttfamily,keywordstyle={},keywordstyle=[1]{}]‌​}. Then is when I've defined morekeywords. – Filip Ekberg Feb 16 '12 at 6:40

Another option, is to use \lst@ifdisplaystyle\ ... \fi to define different keywordstyle's for lstinline and lstlisting.

\documentclass{article}
\usepackage{listings,xcolor}
\makeatletter
\lstset{
language=C,
basicstyle=\ttfamily,
keywordstyle=\lst@ifdisplaystyle\color{blue}\fi,
commentstyle=\color{gray}
}
\makeatother

\begin{document}
\begin{lstlisting}
int a=3; // blue keyword in a lstlisting evironment
\end{lstlisting}

Inline listings are still black: \lstinline{int a=3;}.

\end{document}


-