![在 NewEnviron 中使用自定义字段](https://linux22.com/image/327980/%E5%9C%A8%20NewEnviron%20%E4%B8%AD%E4%BD%BF%E7%94%A8%E8%87%AA%E5%AE%9A%E4%B9%89%E5%AD%97%E6%AE%B5.png)
我想在自定义环境中使用自定义函数。我添加了一个示例,显示该函数在环境外部工作正常,但在环境内部myenv
,它似乎myarr
保持为空。我真的不明白为什么。
\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}