0

I'm lazy and I want to save on typing.

So I have

\newcommand{\bv}{\begin{verbatim}}
\newcommand{\ev}{\end{verbatim}}

\bv
Hi, this should be verbatim
\ev

in my document, but this produces an error:

Runaway argument?
^^MHi, this should be verbatim^^M\ev^^M^^M\end{document}^^M
! File ended while scanning use of \@xverbatim.

What's the matter here?

  • 1
    Short answer: you can't. And you shouldn't anyway. – egreg May 17 '18 at 20:58
  • you can not put verbatim in another command. – David Carlisle May 17 '18 at 20:58
  • 2
    by its nature verbatim stops \ev expanding so the end of the environment is never seen. – David Carlisle May 17 '18 at 20:59
  • I can't put verbatim into another command? Now I like LaTeX much less... :( – user258532 May 17 '18 at 21:02
  • 1
    Latex doesn't care :) (I was told) – Dr. Manuel Kuehner May 17 '18 at 21:06
  • If you're ambitious and are willing to switch to LuaLaTeX (or if you've already done so...), take a look at the query How to handle verbatim material in LuaLaTeX. The main answer to that query (shameless self-citation alert!) provides a way for dealing with verbatim material that's much more flexible and far less restrictive than the ways of "classic", i.e., pdfLaTeX are. – Mico May 17 '18 at 21:10
  • Also related: https://tex.stackexchange.com/questions/86071 – Dr. Manuel Kuehner May 17 '18 at 21:11
  • If you're editing with vi, you create a three line file whose first line says \begin{verbatim}, whose second line is blank, and whose third line says \end{verbatim}, and then on each of the five-thousand occasions in your document where you want to use this, you type a colon to get into command mode, then the letter r followed by a blank space, then the file name. It inserts the content of that file into what you're editing. – Michael Hardy May 17 '18 at 21:31

0 Answers0