26

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}

  • 1
    Use \protect before \verb+@interface+ – azetina Nov 23 '12 at 3:17
  • 2
  • 1
    For simple spells like @interfcae I'd just write \subsubsection{The \texttt{@interface} Section}. When the spells have braces({}) in them, just escape them: \{` or \}. – user10274 Nov 23 '12 at 4:09
  • Thanks to all for your helping. The type of document that I write is a report; I tried with all methods, but the only one that works for me is the \texttt{}, although I use the cprotectand fancyvrb packages. – Isai Nov 23 '12 at 4:13
20

Use the cprotect package:

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

However, consider reading through the informative UK 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.

13

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

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.