[Tex/LaTex] \verb in custom command

macrosverbatim

I have \newcommand\dd[2]{\item[\texttt{#1}] #2} and later I have

\dd{bc}{text \verb#$(echo 5+4 | bc)# text \verb#$((5+4))# text}

and I get

! You can't use `macro parameter character #' in math mode.
<argument> ...nicht mit \verb ##$(echo 5+4 | bc)##
rechnen, sondern die neue...
l.74 ...ekten Rechnen, \verb#$((5+4))#, benutzen.}
Sorry, but I'm not programmed to handle this case;
I'll just pretend that you didn't ask for it.
If you're in the wrong mode, you might be able to
return to the right one by typing `I}' or `I$' or `I\par'.

How can I get the verbatim into my command without the command interpreting it wrongly?

Best Answer

I'm not sure I fully understand what you're trying to achieve, but I think the simplest solution may be something along the following model. Note that one has to "escape" the dollar sign by prefixing a backslash to it; on the other hand, it's not necessary to introduce verbatim strings explicitly.

\documentclass{article}
\newcommand\dd[2]{\item[\texttt{#1}] #2}
\begin{document}
\begin{description}
\dd{bc}{text \texttt{\$(echo 5+4 $|$ bc)} text \texttt{\$((5+4))} text}
\end{description}
\end{document}

enter image description here

Related Question