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}

5
  • 1
    Use \protect before \verb+@interface+
    – azetina
    Nov 23, 2012 at 3:17
  • 3
    Related: How to put \verb command inside of \textbf{} block?
    – Werner
    Nov 23, 2012 at 3:21
  • 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, 2012 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, 2012 at 4:13
  • 5
    (the 2 questions are really exactly identical, not just "related". it's interesting how the (question, top answer) has the exact same number of votes though)
    – user202729
    Apr 3, 2022 at 8:00

2 Answers 2

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.

1
  • Tip: if the command contains non-letter characters, enclose it inside curly braces, e.g., \cprotect{\section*}{\verb"@ interface"}.
    – Eli4ph
    Apr 14, 2022 at 8: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

2
  • 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, 2012 at 10:48
  • There's also \lstinline which does allow adding special characters, but in an inconvenient syntax. (mentioned in tex.stackexchange.com/a/152412/250119 )
    – user202729
    Mar 30, 2022 at 13:46

Not the answer you're looking for? Browse other questions tagged .