[Tex/LaTex] How to format an inline source code

codeformattingline-breakingline-spacinglistings

I have a document where I quiet often refer to source code element, such as class names, I wanted to format these strings differently, but at the beginning I didn't want to fiddle with various options I had, rather I defined my custom command as follows:

\providecommand{\inlinecode}[1]{\texttt{#1}}

Now my question is, what do you think is the best way to define \inlinecode? Note: I often use text with unescaped <, >, e.g., List<T>.

The \texttt looks fine to me, and works with <, >, but sometimes the words overflow the line. Is there any way to tell latex not to overflow the line, but rather "underflow" or insert more spaces between words, which seems to me as (maybe still ugly but) more acceptable than overflow? And is it possible to achieve it by only changing definition of my command, so I won't have to change the whole source?

Best Answer

use package listings instead. Then you can use \lstinline|<List>|. You can define the setting with \lstset{...}. A backgroundcolor is possible with a \colorbox:

\colorbox{blue}{\lstinline[basicstyle=\ttfamily\color{white}]|<List>|}