It depends on what you want the verbatim to support. If you simply want to put some normal text in "verbatim" (typewriter) font, then use \texttt
. If you want to allow special characters such as _
, &
, or ^
to be displayed as is, then \listinline
(which xport mentions) may be enough, and allows to customize the font somewhat.
However, #
or %
will still give you trouble if you don't somehow tell the surrounding command that they are there: for instance, as soon as %
is read from the file the first time, TeX ignores the rest of the line, and there is no way to retrieve it. Here you will have two options that I know of: either save the offending piece of verbatim text prior to using it, for instance with newverb
, or tell the surrounding command to first read its argument verbatim, via the cprotect
package.
\documentclass{article}
\usepackage{cprotect}
\begin{document}
Try \cprotect\textbf{this \verb|%ther #pt\on|}.
\end{document}
Actually, in the case of \textbf
and other font commands, you can also use the corresponding switch, \bfseries
, as in {\bfseries this \verb|%&#| example}
.
\verb
inside any other command's argument (apart from some commands which are specially made to support this, by not really using an argument here).