2

The MWE below, by using paralist package, is supposed to allow \begin{enumerate}[...] where ... is flexible in "some way" (inherits from enumerates above).

\documentclass[a4paper,10pt]{report}

\usepackage{paralist,xargs}

\newcommand\mwe[2]{[{\ref{#1}.}.#2]}

\begin{document}

\newenvironmentx{enumwe}[2][2=1]{%
  \begin{enumerate}\mwe{#1}{#2}%
  %\expandafter\begin\expandafter{\expandafter enumerate\expandafter}\mwe{#1}{#2}%
  \ignorespaces%
}{\end{enumerate}%
  \ignorespacesafterend%
}

\begin{enumerate}[{A}1]

\item \label{one} {\bfseries~Appendix One}

  \begin{enumwe}{one}
    \item text
  \end{enumwe}

\end{enumerate}

\end{document}

However, the commented line seems a wrong attempt, while the MWE typesets wrong.

The expanded result expected would be the following.

\begin{enumerate}[{A}1]
\item \label{one} {\bfseries~Appendix One}
  \begin{enumerate}[{A1.}1.]
    \item text
  \end{enumerate}
\end{enumerate}

I appreciate any help or suggestions.

P.S.: I actually need to expand a macro in the optional parameter to enumerate environment, like \begin{enumerate}[\mwe{...}1.], but it's not working (the ?? occurs everywhere) and this MWE is my approach, but I got stuck with the weird error:

! LaTeX Error: \begin{enumerate} on input line 21 ended by \end{enumerate}.
  • 1
    You should use the package enumitem instead which is more flexible and allows what you want to achieve. – Marco Daniel Aug 17 '12 at 16:24
  • @MarcoDaniel: sorry, all the rest of the class core code involved is based on paralist, for now. – sjb Aug 17 '12 at 16:58
3

\expandafter only steps over a single token not brace groups, so the simplest thing is to put everything you want to step over into a single token:

\documentclass[a4paper,10pt]{report}

\usepackage{paralist,xargs}

\newcommand\mwe[2]{[{\ref{#1}.}.#2]}

\begin{document}

\newenvironmentx{enumwe}[2][2=1]{%
  \def\temp{\begin{enumerate}}%
  \expandafter\temp\mwe{#1}{#2}%
  \ignorespaces%
}{\end{enumerate}%
  \ignorespacesafterend%
}

\begin{enumerate}[{A}1]

\item \label{one} {\bfseries~Appendix One}

  \begin{enumwe}{one}
    \item text
  \end{enumwe}

\end{enumerate}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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