答案1
注释后已修改。这是我在 expl3 中编写的第一个程序,我们应该可以做得更好。
\documentclass{article}
\ExplSyntaxOn
\newcommand{\theelement}[1]{
% outputs the #1-th token in \l_element_group_seq
\seq_item:Nn \l_element_group_seq {#1}
}
\newcommand{\thejust}[1]{
% outputs the #1-th token in \l_just_tl
\clist_item:Nn \l_just_tl {#1}
}
\clist_new:N \l_just_tl
\newcommand{\Ljust}[1]{
\clist_set:Nn \l_just_tl {#1}
}
\seq_new:N \l_element_group_seq
\NewDocumentCommand\just{ O{\item} m }
% #1 is \item
% #2 the list of items in enumerate
{
%
\seq_set_split:Nnn \l_element_group_seq {#1} {#2}
\seq_remove_all:Nn \l_element_group_seq {}% remove the empty before the first item
\clist_if_empty:NTF \l_just_tl
{
% if Ljust is empty
\int_step_inline:nn {\seq_count:N \l_element_group_seq}
{%
\item \theelement{##1}}% all item
}
{
\int_step_inline:nn {\clist_count:N \l_just_tl}
{%
\item \theelement{\thejust{##1}}% item of Ljust
}
}
}
\ExplSyntaxOff
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\Ljust{1,2,4}
Many items
\begin{enumerate}
\just{%
\item text A
\item $5\times3$
\item text C
\item text D
}%
\end{enumerate}
\Ljust{4,2,1,3}
Some text in 'not order"
\begin{enumerate}
\just{%
\item text A
\item $5\times3$
\item text C
\item text D
}%
\end{enumerate}
\Ljust{}
All items in the order
\begin{enumerate}
\just{%<--- you can also comment
\item text A
\item $5\times3$
\item text C
\item text D
}%<--- you can also comment
\end{enumerate}
\end{document}