I have the following code:
\documentclass{minimal}
\newenvironment{abc}
{\begin{verbatim}}
{\end{verbatim}}
\begin{document}
% This works.
\begin{verbatim}
abc
\end{verbatim}
% This does not work.
\begin{abc}
abc
\end{abc}
\end{document}
I am trying to create a custom environment that uses verbatim
. But the above code does not work. How should I do this?
Best Answer
It depends on the verbatim environment in question.
Environment
verbatim
of packageverbatim
If you load package
verbatim
, then its environmentverbatim
can be used inside other environment definitions as long it is not hidden inside other groups. Also, it cannot be used as\begin{verbatim}
, becauseverbatim
needs to know the name of the parent environment to find the end tag\end{<parent>}
. The parent environment name would be overwritten by the LaTeX code for\begin
.Example:
Package
fancyvrb
Custom verbatim environments can be created by
\DefineVerbatimEnvironment
, example from the documentation, slightly modified:Package
listings
Environments can be defined with
\lstnewenvironment
. Example from the documentation: