I'd like to use a self-defined function inside a self-defined environment. I add an example showing, that the function work perfect outside the environment, but inside the environment myenv, it seems that myarr stays empty. I really don't get why.
\documentclass{article}
\usepackage{pgfmath,pgffor}
\usepackage{environ}
\newcounter{lines}%
\def\endlr{\stepcounter{lines}\\}
\newcommand*\myarr{}%
\newcommand{\mtadd}{%
\ifx\myarr\empty
\edef\myarr{\arabic{lines}}
\else\edef\myarr{\myarr,\arabic{lines}}
\fi}
\NewEnviron{myenv}[1][]{%
\myarr\empty%
\setcounter{lines}{1}%
}
\def\names{{"Katie","Frank","Laura","Joe","Peter","Jens","Carolin","Anna","Steph","Stef"}}
\begin{document}
\setcounter{lines}{3}
\mtadd
\foreach \i in \myarr {%
Name \i: \pgfmathparse{\names[\i]}\pgfmathresult, }
\begin{myenv}
\mtadd
\endlr\endlr
\mtadd
\foreach \i in \myarr {%
Name \i: \pgfmathparse{\names[\i]}\pgfmathresult, }
\end{myenv}
\end{document}
myenvenvironment should do, but you're forgetting to use\BODY, which stands for the environment's contents in the definition. – egreg Feb 10 '16 at 23:07NewEnvirondefinition produces the error `! Illegal parameter number in definition of \pgfkeyscurrentkey.