TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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?

share|improve this question
up vote 6 down vote accepted

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


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

enter image description here

share|improve this answer
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.


int a=3; // blue keyword in a lstlisting evironment

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


enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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