5

For making a report of my work, I am facing a problem of writing varbatim too frequently. So, I need a workout. Say, I define a newcommand as (for example)

\newcommand{\uve}{\textbf{In verbatim}}  %there must be something more

now, if I invoke

\uve <some text>

the effect should be as

\textbf{in verbatim}
\begin{verbatim}
<some text>
\end{verbatim}

I tried using

\providecommand{\uve}[1]{\\\textbf{In Verbatim:~}\begin{verbatim}{#1}\end{verbatim}}

and failed, with error: Runaway argument?

{/}\end {verbatim}<some text>^^M\stat Complete\ETC.
! File ended while scanning use of \@xverbatim.
<inserted text> 

Kindly help.

Edit after 3 comments For my present purpose, \verb is sufficient. but, I need to define an environment (sorry, not a command as I put in OP) that will give me:

\begin{verbenv}
 some text
\end{verbenv}

will directly give me:

**In verbatim:** Some text
6
  • @barbarabeeton I had thought the point was about macro vs. environment. But I see your point. I will delete my prior comment. Dec 5, 2013 at 15:03
  • @barbarabeeton: Using that example directly will need me to add some more text as \begin{codeframe}{example} ... not much save in typing.
    – BaRud
    Dec 5, 2013 at 15:13
  • 1
    The environment verbatim is pretty special, since it must end with \end{verbatim}. Hence, taking this environment as a part of a control sequence or new environment will get an ERROR. The package fancyvrb will help you.
    – Ch'en Meng
    Dec 5, 2013 at 15:19
  • 1
    Does <some text> contain any weird characters?
    – Werner
    Dec 5, 2013 at 15:19

1 Answer 1

6

Just define a new environment. The simplest way is with the verbatim package:

\documentclass{article}
\usepackage{verbatim}
\newenvironment{inverb}
 {\par\addvspace{\topsep}\noindent\textbf{In verbatim}\nopagebreak
  \verbatim}
 {\endverbatim}

\begin{document}

Something before
\begin{inverb}
some text
\end{inverb}
Something after

\end{document}

With fancyvrb you can do more customizations.

enter image description here

You must log in to answer this question.

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