TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to define a verbatim{} command that I could use instead of the environment?

share|improve this question

As Stefan has said, fancyvrb is usually the way to go. However, it’s not straightforward to use in an environment since the relevant macro is undocumented1).

Here’s a minimal working example:



    % First, we tell fancyvrb that we're inside a verbatim environment.
    \textbf{Source code ``#1'':}\\
    % Now we start the actual environment:


The comment % right behind the \begin{Verbatim}… is important – otherwise, the compiler will complain with horrible, undecipherable error messages. The same will happen for any other error you make, so be careful.

The \VerbatimEnvironment command is equally crucial, and undocumented.

1) For simple cases, using the (documented) \DefineVerbatimEnvironment may be enough, but the above example cannot be written with it.

share|improve this answer
This creates a verbatim environment, not a verbatim command, which I think the OP wanted. – hadley May 18 '13 at 18:59

If you need further functionality, have a look at the fancyvrb package, it provides further environments and commands for flexible handling of verbatim text.

share|improve this answer

Why not use \verb?


 Foo \verb|\bar| baz
share|improve this answer
I thought of the inline \verb, but I need something that can span over several lines. – landroni Aug 7 '10 at 11:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.