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.

See the question below:

\documentclass{article}
\usepackage{listings}

\begin{document}
Here is some text where I would like to talk about a particular
variable called \lstinline|var|.  How can I visually set off
\lstinline|var| as something special without being too ridiculous?
\end{document}

Current output as demonstration:

output


How can I change inline listings without also changing the style for displayed listings?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

Usually it's enough to use mono-spaced font (and perhaps a smaller font size) and this can be done using the optional argument for \lstinnline or, better yet, defining a short variant with the desired options already included:

\documentclass{article}
\usepackage{listings}

\lstMakeShortInline[basicstyle=\small\ttfamily]|

\begin{document}
Here is some text where I would like to talk about a particular
variable called \lstinline[basicstyle=\small\ttfamily]|var|.  How can I visually set off
\lstinline[basicstyle=\small\ttfamily]|var| as something special without being too ridiculous?

Here is some text where I would like to talk about a particular
variable called |var|.  How can I visually set off
|var| as something special without being too ridiculous?

\end{document}

enter image description here

And, of course, you can also add some other properties (a color, for example):

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}

\lstMakeShortInline[basicstyle=\small\ttfamily\color{cyan}]|

\begin{document}
Here is some text where I would like to talk about a particular
variable called \lstinline[basicstyle=\small\ttfamily\color{cyan}]|var|.  How can I visually set off
\lstinline[basicstyle=\small\ttfamily\color{cyan}]|var| as something special without being too ridiculous?

Here is some text where I would like to talk about a particular
variable called |var|.  How can I visually set off
|var| as something special without being too ridiculous?

\end{document}

enter image description here

share|improve this answer
    
I should probably add to the original question that I would not like to also change the style for displayed listings; my apologies. –  Sean Allred Feb 27 at 4:53
1  
@SeanAllred No need to apologize :) Please see my updated answer. –  Gonzalo Medina Feb 27 at 4:59

Another option is to define a new style, for example

\lstdefinestyle{inline}{%
   basicstyle=\small\ttfamily\color{red}
}

and use it for \lstinline regardless of the character used to encase the listing:

\lstinline[style=inline]|var|
\lstinline[style=inline]!var!

MWE:

\documentclass{article}
\usepackage{listings,xcolor}

\lstdefinestyle{inline}{%
   basicstyle=\small\ttfamily\color{red}
}

\begin{document}
Here is some text where I would like to talk about a particular
variable called \lstinline[style=inline]|var|.  How can I visually set off
\lstinline[style=inline]!var! as something special without being too ridiculous?
\end{document} 

Output:

enter image description here

share|improve this answer

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.