8

I have an environment that I've defined as follows:

\newenvironment{regularEnumerateEx}[2][0em]
  {begin{listSkeleton}[#1]{enumerate}{#2}}
  {\end{listSkeleton}}

The problem is that I need to expand #2 before passing it to listSkeleton. It's okay if #1 is expanded (I think). I know I have to use \expandafter in some way, but not exactly how.

lockstep
  • 250,273
gablin
  • 17,006

1 Answers1

12

If it is OK to expand it completely, not just once you can use \edef with a temporary macro:

\newenvironment{regularEnumerateEx}[2][0em]{%
  \edef\temp{%
    \noexpand\begin{listSkeleton}[#1]{enumerate}{#2}%
  }%
  \temp
}{%
  \end{listSkeleton}%
}

If you really only want to expand it once you can do:

\newenvironment{regularEnumerateEx}[2][0em]{%
  \def\temp{\begin{listSkeleton}[#1]{enumerate}}%
  \expandafter\temp\expandafter{#2}%
}{%
  \end{listSkeleton}%
}

Often the macro \@tempa is used for such temparary assignments, but in user documents it requires \makeatletter ... \makatother around the code. So for simplicity I just used \temp. It is anyway just used inside a group.

Martin Scharrer
  • 262,582