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.

It looks like you can't use \verb|...| inside of \textbf{...}. I tried the following:

\textbf{Be very careful when using \verb|-i| as it's destructive and it's not reversible!}

And got this error:

! LaTeX Error: \verb illegal in command argument.

Any ideas?

share|improve this question
6  
More generally, you can't use \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). –  Paŭlo Ebermann Jul 31 '11 at 18:14

3 Answers 3

up vote 15 down vote accepted

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}.

share|improve this answer

Use listings package, it is very useful and can be used everywhere, either in section heading or body.

enter image description here

\documentclass{article}
\usepackage{xcolor,listings}
\lstset
{
    language={[LaTeX]TeX},
    basicstyle=\tt\color{red},
}
\begin{document}
\section{This is an inline listing in \lstinline|section|}
Remember \lstinline|I can find| a tool to convert PDF to EPS
\lstinline!in my! neither bathroom nor kitchen.
\end{document}
share|improve this answer

use \texttt instead and a monotype font which supports a bold typeface. \verb cannot be inside another macro.

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.