# parameter passing to \verb|| environment

I happen to write the following code over and over again.

{\color{blue}\verb|>|} {\footnotesize\verb|HI|}


So, I came up with the following code to make it a command.

\newcommand{\result}[2]{%
{\color{#1}\verb|>|} {\footnotesize\verb|#2|}
}



\end{document}

-

With a modicum of coercion, the verbatim package can be made to almost do what you want. The "almost" is because you have to use an environment instead of a command.

\documentclass{article}

\usepackage{verbatim}
\usepackage{xcolor}

\makeatletter
\newenvironment{result}[1]{%
\def\verbatim@processline{\the\verbatim@line\ }%
\def\@verbatim{\the\every@verbatim
\obeylines
\let\do\@makeother \dospecials
\verbatim@font
}%
\def\endverbatim{\endgroup}%
\noindent
{\color{#1}\texttt{>}}
\footnotesize
\verbatim}{\endverbatim}
\makeatother

\begin{document}

\begin{result}{red}
greetings
\end{result}

\begin{result}{green}
A load of *@&$!)%*#$
\end{result}

\end{document}


In short, I looked a the definitions in the verbatim package and stripped out everything that looked as though it might insert a newline, thus making the verbatim environment work on one line instead of several and meaning that it doesn't start or end with new lines. Then I put this inside a new environment so that the old \begin{verbatim} ... \end{verbatim} construct still works as it should.

Caveat: Anything extra on the line \end{result} gets discarded (LaTeX warns about this). So if you want to take out the \noindent from the result environment and have the input more like in the example in the question, the code will have to be:

\noindent\begin{result}{red}
greetings
\end{result}
\\
\begin{result}{green}
A load of *@&$!)%*#$
\end{result}

-