I'm trying to create an alias for the verbatim environment like this:

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

So I can use it like this:


But when using it, I get this error:

! Missing $ inserted.
<inserted text> 
l.93 \end{verbatim}

Where line 93 is the end of a verbatim environment I used after later down the file after closing the \vb. If I replace all verbatim environments with the \vb syntax, then I get this error:

Runaway argument?
zip([],B) = case ([],B) of ([],_) => [] | (_,[]) => [] | (x::L,y::R\ETC.
! File ended while scanning use of \@xverbatim.
<inserted text> 

So it seems like the \vb is not closing the environment correctly? How do I get this to work ? The end goal is to get a \vb command that I can use like I described above, and bonus points if I could indent the stuff in the \vb command by a few mm.

  • 1
    As far as I know, there’s no way in replacing the environment with a command. Nonetheless you should take a deep look into the fancyvrbdocumentation.
    – Speravir
    Sep 18, 2012 at 2:29
  • If you just want oneline verbatim text, you could use a \Verb variant in Fancyvrb.
    – Speravir
    Sep 18, 2012 at 2:32
  • 1
    Your statement "So it seems like the \vb is not closing the environment correctly" is absolutely correct. Tokens are scanned in search of \end{verbatim} and is never found.
    – Werner
    Sep 18, 2012 at 5:26
  • 1
    Werner forgot to provide the following link (I found it in another answer of him) from the UK TeX FAQ: Why doesn’t verbatim work within …?.
    – Speravir
    Sep 18, 2012 at 22:41
  • Somewhat related: Verbatim inside a command - TeX - LaTeX Stack Exchange
    – user202729
    Jan 5, 2022 at 12:53

1 Answer 1


A general rule is that you can't have \begin{verbatim} or the \verb command in the argument to another command, including an argument to \newcommand.

If you really want to use that syntax, you of course can't have braces in the argument and hope that they will be printed as themselves: either they delimit the argument or they must be printed.

If this limitation satisfies you, then

  \catcode`{=1 \catcode`}=2 \catcode` =10

will allow you to write


I don't think this is a great improvement than saying


If you want a margin indent of the verbatim, look at the option xleftmargin in to the Verbatim environment provided by the package fancyvrb.

You must log in to answer this question.

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