28

I have a question about a Verbatim, I want to write a word inside of the subsubsection title. I got an error. How can I fix it?: \subsubsection{The \verb+@interface+ Section}

Isai
  • 4,153

2 Answers2

23

Use the cprotect package:

\usepackage{cprotect}% http://ctan.org/pkg/cprotect
...
\cprotect\subsubsection{The \verb+@interface+ Section}

However, consider reading through the informative TeX FAQ entry: Why doesn’t verbatim work within …? In particular, other alternatives like \texttt{...} also exist and are far more manageable. Even in your case, using

\subsubsection{The \texttt{@interface} Section}

works as-is.

Werner
  • 603,163
  • Tip: if the command contains non-letter characters, enclose it inside curly braces, e.g., \cprotect{\section*}{\verb"@ interface"}. – Eli4ph Apr 14 '22 at 08:55
15

The standard \verb command cannot be used in the argument of other commands. You can use \Verb from the fancyvrb package:

\documentclass{article}
\usepackage{fancyvrb}

\begin{document}

\subsubsection{The \protect\Verb+@interface+ Section}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • 2
    While this works, it still doesn't allow for adding special characters in the argument to \Verb, so the simpler \texttt might be better. – egreg Nov 24 '12 at 10:48
  • There's also \lstinline which does allow adding special characters, but in an inconvenient syntax. (mentioned in https://tex.stackexchange.com/a/152412/250119 ) – user202729 Mar 30 '22 at 13:46