2

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?

2

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.

  • well, I want to collect the body to patch particular code strings and pass the result on to itemize. – Jesse op den Brouw Aug 17 '18 at 18:16
  • @JesseopdenBrouw: Does your code string contain particularly odd characters? – Werner Aug 17 '18 at 18:39
  • 1
    @JesseopdenBrouw: Try this. It works, partially... – Werner Aug 17 '18 at 19:12
  • It looks promising... – Jesse op den Brouw Aug 17 '18 at 19:46
  • For now. I will do with \renewenvironment{verbatim}[1]{\begingroup\ttfamily #1}{\endgroup} – Jesse op den Brouw Aug 17 '18 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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