I am trying to create a simple function that takes in some lowercase letters a,b,r,e,r etc removes any duplicate letters, and sort them. Then I want to list the output in a list
Input:
\supportMaterials{r,r,e,a}
Output:
\begin{enumerate}
\item a
\item e
\item r
\end{enumerate}
- I tried to use the following code: https://tex.stackexchange.com/a/333666/8306. To create a sorted list, however, no output is given when I try to enumerate the list. Perhaps it expands too late?
- In addition I am not quite sure how to remove duplicates.
Here is my attempt so far
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\usepackage{expl3,xparse,xstring}
\ExplSyntaxOn
\prg_new_conditional:Nnn \john_string_if_before:nn { p,T,F,TF }
{% I hope the LaTeX3 police won't catch me
\int_compare:nTF { \pdftex_strcmp:D { #1 } { #2 } < 0 }
{
\prg_return_true:
}
{
\prg_return_false:
}
}
\NewDocumentCommand{\sortlist}{smm}
{
\IfBooleanTF{#1}
{
\clist_set:No \l__john_sortlist_data_clist { #2 }
}
{
\clist_set:Nn \l__john_sortlist_data_clist { #2 }
}
\john_sortlist:N \l__john_sortlist_data_clist
\clist_set_eq:NN #3 \l__john_sortlist_data_clist
}
\clist_new:N \l__john_sortlist_data_clist
\cs_new_protected:Nn \john_sortlist:N
{
\clist_sort:Nn #1
{
\john_string_if_before:nnTF { ##1 } { ##2 }
{
\sort_return_same:
}
{
\sort_return_swapped:
}
}
}
\NewDocumentCommand\supportMaterialHelp{m}{%
\IfStrEqCase{#1}{%
{r}{R}%
{b}{B}%
{k}{K}%
{c}{C}%
{a}{A}%
{e}{E}%
}[]%
}
\NewDocumentCommand{\supportMaterial}{ m }
% Input is a list {r,b,k,...} which is defined in the function
% \supportMaterialHelp above. This code loops through the values
% and creates an enumerate with the values
{%
\sortlist{#1}{\sortedInputList}%
\begin{enumerate}[label={--}]%
% This works fine
\clist_map_inline:nn { #1 } { \item \supportMaterialHelp{##1} }
% Why does this fail to work?
\clist_map_inline:nn { \sortedInputList } { \item \supportMaterialHelp{##1} }
\end{enumerate}
}
\ExplSyntaxOff
\begin{document}
\supportMaterial{r,e,k}
\end{document}


\exp_args:No \clist_map_inline:nn { \sortedInputList } ...– Ulrike Fischer Aug 08 '19 at 15:12