I try to sort enumerated lists in latex. All I found is how to sort items by their ordinal number (see Order items in enumerate environment automatically):
\documentclass{article}
\usepackage{pgffor}
\makeatletter
\newcounter{SortListTotal}
\newcommand{\sortitem}[1]{\stepcounter{SortListTotal}\expandafter\def\csname SortItem\arabic{SortListTotal}\endcsname{#1}}
\newcommand{\printsortlist}[1]{\@for\currentitem:=#1\do{\item\csname SortItem\currentitem\endcsname}\setcounter{SortListTotal}{0}}
\makeatother
\begin{document}
\begin{enumerate}
\sortitem{This is the third item.}
\sortitem{This is the fourth item.}
\sortitem{This is the first item.}
\sortitem{This is the second item.}
\printsortlist{3,4,1,2}
\end{enumerate}
\end{document}
Could you please help me how to rewrite \sortitem and \printsortlists such that I can use the following code:
\newcommand{\nc}{three,four,one,two}
\begin{enumerate}
\sortitem{one}{This is the third item.}
\sortitem{two}{This is the fourth item.}
\sortitem{three}{This is the first item.}
\sortitem{four}{This is the second item.}
\printsortlist{\nc}
\end{enumerate}
If it is not an easy task, I would also be happy if you provide an alternative solution to this problem.
