I'm looking for a way to nicely set code inside my document. I used \def\code#1{{\texttt{#1}}}, but it still allows the text to be hyphenated. To prevent that, I tried the advise from Prevent hyphenation and use line break in block of text and tried \def\code#1{{\mbox{\texttt{#1}}}}, but then the font size is lost when I write, for example, T_{\code{FOO}}. Unfortunately, the \nohyphens{...} solution clashed with some other package (as I understand it) and the \hyphenpenalty 10000 solution produced no changes.
While preparing the MWE I found that the hyphenation only happens after underscores.
It can't be that hard to get what I want, or is it?
Here is an MWE:
\documentclass{article}
\def\code#1{{\texttt{#1}}}
%\def\code#1{{\mbox{\texttt{#1}}}}
\usepackage[strings]{underscore}
\begin{document}
I really like to use \code{assert()}. Still,
\code{assertions_that_should_never_fail_even_if_they_stick_out()}
should not be hyphenated. I know some long words:
pneumonoultramicroscopicsilicovolcanoconiosis,
parastratiosphecomyia stratiosphecomyioides,
pseudopseudohypoparathyroidism,
floccinaucinihilipilification,
subdermatoglyphic,
squirrelled,
abstentious and
rotavator.
Function \code{FOO} runs in time $T_{\code{FOO}}$, not $T_{FOO}$.
\end{document}

\verb+Here is my code.+Any character (except*) can be used to delimit the verbatim text, as long as it doesn't appear in the text itself, obviously. – ChrisS Apr 08 '14 at 10:26LaTeX Error: \verb illegal in command argument.– cxxl Apr 08 '14 at 10:34\code{}but warnings in the log. Your solution works fine! Thanks again. – cxxl Apr 08 '14 at 10:50