[Tex/LaTex] newcommand for verbatim

macrosverbatim

I'm trying to write a \newcommand for verbatim:

\newcommand{\codeline}[1]{\begin{verbatim}{#1}\end{verbatim}}

and use it as

\codeline{int foo;}

but it gives an error "File ended while scanning use of \@xverbatim". How to fix it?

Best Answer

If you want a simple implementation, go with

\newcommand[1]{{\small\texttt{#1}}}

If you want more detailed control, you should go with fancyvrb or minted packages.

Related Question