Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

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}

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
add comment

Your Answer

 
discard

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.