Import only a few predefined items from an enumerate environment

#enumerateenumitem

Is there a command that allows you to import only a few items from an enumerate environment?

\documentclass{article}
\usepackage{enumitem}

\begin{document}


\begin{enumerate}
\item A
\item B
\item C
\item D
\end{enumerate}


Desired output :
% with some commande such that : \just{1,2,4}
\begin{enumerate}
\item A
\item B
\item D
\end{enumerate}

\end{document}

enter image description here

Best Answer

MODIFIED after the comment. This is my first program in expl3, we should be able to do much better.

    \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}