# Use verbatim inside \newcommand [duplicate]

Probably this was already answered. But I did not find it. How can I use verbatim inside \newcommand{} or \begin{environment}...\end{environment}. In my MWE, the last two lines produce errors.

\documentclass{article}

\newcommand{\FIXME}[1]{#1}
\newcommand{\FIXMA}[1]{\verb+#1+}

\begin{document}
\noindent
\verb+test test test+ \\
\FIXME{test test test}
\FIXME{\verb+test test test+}
\FIXMA{test test test}
\end{document}


## marked as duplicate by Werner, Svend Tveskæg, Mensch, user11232, OSjerickOct 14 '15 at 2:35

• You can't use \verb in the argument to another command. But do you really need \verb? – egreg Oct 13 '15 at 21:26
• \texttt{\detokenize{#1}} probably does the right thing if you are using \usepackage[T1]{fontenc} – David Carlisle Oct 13 '15 at 21:46
• To wit, the relevant portion of egreg's answer would seem to be \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\showcase}{v} { \texttt{#1} } \ExplSyntaxOff – Steven B. Segletes Oct 13 '15 at 23:44
• Also, depending on what you seek, my verbatimbox package may be useful. The verbbox environment saves verbatim content into a LaTeX box, which can be recalled, either on the command line, or inside a macro with \theverbbox. – Steven B. Segletes Oct 13 '15 at 23:50
• Here is a verbatimbox example. Let me know if it is relevant. \documentclass{article} \usepackage{verbatimbox} \newcommand{\FIXME}[1]{$>>>$#1$<<<$} \begin{document} \noindent $>>>$\verb+test test test+$<<<$ \\ \FIXME{test test test}\\ \begin{verbbox}test test test\end{verbbox} \FIXME{\theverbbox}\\ \end{document} – Steven B. Segletes Oct 13 '15 at 23:58

There are several things that came to mind, when reading this question.

POSSIBILITY 1) \detokenize

David suggested this in a comment. The OP responded that he/she was unhappy with the space that \detokenize automatically introduces after macro names. That reminded me of this question, Print small TeX code verbatim and render it, which provided two answers. Egreg's accepted answer used an \ExplSyntaxOn approach (xparse package) in which

\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\showcase}{v} { \texttt{#1} }
\ExplSyntaxOff


provides a verbatim macro. My timid attempt to incorporate this inside of another macro was unsuccessful, but I am unversed at \ExplsyntaxOn to know whether egreg's approach could be adapted for the needs of the OP.

The other answer at that question was my own, in which I introduced \detokenizeplus, to trap the annoying spaces and try to eliminate them. While I could make it work for that particular question, the approach was not bulletproof, as I noted in the answer. Nonetheless, there is the chance to employ \detokenizeplus within another macro to get the benefits of the \detokenize approach, but without the annoying spaces.

POSSIBILITY 2: verbatimbox

My verbatimbox package might also have so application here, though it is hard to tell, based on the limited example provided by the OP. What that package's verbbox environment does is to allow verbatim content to be saved inside a LaTeX box, to be later regurgitated with \theverbbox (note there is also a myverbbox environment that allows a unique name of the box to be specified).

So, while the verbatim content cannot be specified inside of a macro with this approach, previously specified verbatim content can be presented (inline) inside of the macro. Here is an example of how that is done:

\documentclass{article}
\usepackage{verbatimbox}
\newcommand{\FIXME}[1]{$>>>$#1$<<<$}
\begin{document}
\noindent
$>>>$\verb+test test test+$<<<$ \\
\FIXME{test test test}\\
\begin{verbbox}test test test\end{verbbox}
\FIXME{\theverbbox}\\
\end{document}


It's not clear to me what you are trying to achieve. If you really need verbatim material, you can use \lstinline from the listings package:

\documentclass{article}
\usepackage{listings}

\lstset{basicstyle=\ttfamily}
\newcommand{\FIXME}[1]{#1}
\newcommand{\FIXMD}{\lstinline}

\begin{document}
\noindent
\FIXME{test \lstinline!test! test}\\
\FIXMD!test \text{AAA} test!
\end{document}


Notice that \FIXMD is really redundant but, as I said, it's not clear to me what the intended really use for the commands should be.