0

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}
PeMa
  • 175
  • 7
  • 2
    It's not clear what the myenv environment 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:07
  • Thanks a lot. Solves this issue. Unfortunately, if I do that in the original program that I mainly copied from the post of Claudio Fiandrino in http://tex.stackexchange.com/questions/196794/how-can-you-create-a-vertical-timeline. The next line after the NewEnviron definition produces the error `! Illegal parameter number in definition of \pgfkeyscurrentkey. 1 l.89 ]` – PeMa Feb 14 '16 at 15:16

0 Answers0