5

I would like to like to use \verb in theorem environment option, but it seems not work as I expected.

\documentclass{article}
\usepackage{amsthm}
\newtheorem*{dfn*}{Definition}
\begin{document}
\begin{dfn*}[\verb|double_integer|]
 \[ \verb|double_integer|(n) := 2n \]
\end{dfn*}
\end{document}

How can I get the desired outcome?

1
  • 3
    as documented in any tutorial \verb does not work in the argument of any command. Use [\texttt{double\_integer}] Commented Jan 23, 2017 at 7:45

1 Answer 1

6

You don't want to use \verb for this, because it can never go in the argument to another command. It's better to define a proper command for such objects. Here's a possibility (\detokenize is used for avoiding problems with the underscore).

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsthm}

\newtheorem*{dfn*}{Definition}
\newcommand{\cfunc}[1]{\textnormal{\texttt{\detokenize{#1}}}}

\begin{document}

\begin{dfn*}[\cfunc{double_integer}]
Some text for the definition
 \[ \cfunc{double_integer}(n) := 2n \]
and something else.
\end{dfn*}

\end{document}

enter image description here

You must log in to answer this question.

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