Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
1  
Do you need to expand it only once or completely? –  Martin Scharrer Aug 18 '11 at 9:54
    
@Martin Scharrer: I'm not familiar enough with LaTeX to comment on that. If expanding it completely is easier and doesn't break anything, then that will suffice. –  gablin Aug 18 '11 at 11:35
add comment

1 Answer

up vote 8 down vote accepted

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.

share|improve this answer
    
In the first code there is a \noexpand missing, right before \begin. Otherwise the \edef will not work. –  Axel Sommerfeldt Aug 18 '11 at 10:33
    
@Axel: Yes, indeed. I overlooked that. Fixed now. –  Martin Scharrer Aug 18 '11 at 10:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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