3

Consider the following MWE:

\documentclass[a4paper]{article}

\usepackage{environ}

\NewEnviron{myitemize} {
\show\BODY
\begin{itemize}
\BODY
\end{itemize}
}

\begin{document}

\begin{itemize}
\item \verb|test|
\end{itemize}

\begin{myitemize}
\item \verb|test|
\end{myitemize}

\end{document}

The first list works, but the second one throws Latex errors (missing } inserted, extra }, \verb illegal ...). It has probably something to do with the way NewEnviron collects it's body but can someone elaborate on this problem.

Log file shows:

> \BODY=macro:
->\item \verb |test|.

so why is there a problem? And of course, what is the solution?

1 Answers1

3

This issue is similar to passing \verb as an argument to a macro, as in

\newcommand{\mymacro}[1]{#1}

\mymacro{\verb|test|}

Your solution in this case would be to not use environ:

\documentclass{article}

\newenvironment{myitemize}
  {\begin{itemize}}
  {\end{itemize}}

\begin{document}

\begin{itemize}
  \item \verb|test|
\end{itemize}

\begin{myitemize}
  \item \verb|test|
\end{myitemize}

\end{document}

Why is there a problem to start with? The collection of content fixes the category codes - something \verb and verbatim needs access to (or change) in order to function properly.

Werner
  • 603,163