\itemize vs. \begin{itemize} not behaving as expected
I want to write a wrapper macro for an itemize environment. I would like
to use the enumitem package (though the MWE here doesn't use or need this
package). The problem is the parameters that I'm passing to the itemize
environment may themselves be encoded inside another macro.
So for the wrapper macro, I wanted to write something like
\expandafter\itemize\expandafter[\anothermacro]
to handle this. But I got very unexpected results.
For some reason, the following two styles to embedding an itemize
environment in a wrapper macro don't work identically.
The first style just uses \begin{itemize} followed by content and then a
closing \end{itemize}.
The second style used \itemize followed by content and then a closing
\enditemize. But in the second style, I get nested environments. Not at
what I'm expecting.
\documentclass{article}
\pagestyle{empty}
\usepackage{xparse}
\ExplSyntaxOn
\clist_new:N \l_ae_itemize_clist
%%--------------------------------------------------------------------------------
%% Style A
\cs_new:Npn \_ae_itemize_a:nn #1#2
{
\clist_set:Nn \l_ae_itemize_clist { #2 }
\begin{itemize}
\clist_map_inline:Nn \l_ae_itemize_clist
{ \item ##1 }
\end{itemize}
}
\NewDocumentCommand{\aefooda}{ O{}mm }
{ \par\textbf{#2:}
\_ae_itemize_a:nn {#1}{#3}
}
%%--------------------------------------------------------------------------------
%% Style B
\cs_new:Npn \_ae_itemize_b:nn #1#2
{
\clist_set:Nn \l_ae_itemize_clist { #2 }
\itemize
\clist_map_inline:Nn \l_ae_itemize_clist
{ \item ##1 }
\enditemize
}
\NewDocumentCommand{\aefoodb}{ O{}mm }
{ \par\textbf{#2:}
\_ae_itemize_b:nn {#1}{#3}
}
\ExplSyntaxOff
\begin{document}
\textbf{Style A} works fine:
\aefooda{first}{a,b,c}
\aefooda{second}{a,b,c}
\aefooda{third}{a,b,c}
%%--------------------------------------------------------------------------------
%% Changing from style A to style B
%%--------------------------------------------------------------------------------
\textbf{Style B} doesn't work:
\aefoodb{first}{a,b,c}
\aefoodb{second}{a,b,c}
\aefoodb{third}{a,b,c}
\end{document}
UPDATE
I've also tried something like the following:
\edef\aeBeginItemize[#1]{\noexpand\begin{itemize}[#1]}
\cs_new:Npn \_ae_itemize_c:nn #1#2
{
\clist_set:Nn \l_ae_itemize_clist { #2 }
\aeBeginItemize[#1]
\clist_map_inline:Nn \l_ae_itemize_clist
{ \item ##1 }
\end{itemize}
}
But when I try to use it, I get an error from the enumitem package: it
seems that enumitem is not longer able to process the keys correctly.
No comments:
Post a Comment