# Latex3 clist contains only one element

I want to use a clist, but I don't understand why it contains only one element. I use the following function

\NewDocumentCommand{\makeenumerate}{ m }
{
\begin{enumerate}
\clist_map_inline:nn { #1 } { \item \fbox{##1} }
\end{enumerate}
}


If I use it the following way

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{expl3}

\ExplSyntaxOn
\NewDocumentCommand{\makeenumerate}{ m }
{
\begin{enumerate}

\clist_map_inline:nn { #1 } { \item \fbox{##1} }
\end{enumerate}
}
\ExplSyntaxOff

\newcommand{\myFilter}{conversion,longueur}

\begin{document}

\makeenumerate{\myFilter}

\end{document}


I get the following:

I would expect to have two items and I have only one. If I call the function with

\makeenumerate{conversion,longueur}


it works as expected. What is the difference ?

I have a more complicated function and the end goal is to pass a clist to that function. My idea was to store the clist in a varibable called myFilter.

Thank you for the help.

• you are not expanding the argument \myFilter has one token and no commas. – David Carlisle May 16 at 17:00

Since you're using expl3, do a further step and use its data types.

\documentclass{article}

\ExplSyntaxOn

\NewDocumentCommand{\defineclist}{mm}
{
\clist_clear_new:c { l__luc_armand_#1_clist }
\clist_set:cn { l__luc_armand_#1_clist } { #2 }
}

\NewDocumentCommand{\makeenumerate}{ m }
{
\begin{enumerate}
\clist_map_inline:cn { l__luc_armand_#1_clist } { \item \fbox{##1} }
\end{enumerate}
}

\ExplSyntaxOff

\defineclist{myFilter}{conversion,longueur}

\begin{document}

\makeenumerate{myFilter}

\end{document}


You can even build your lists in pieces, for instance with

\NewDocumentCommand{\addtoclist}{mm}
{
\clist_put_right:cn { l__luc_armand_#1_clist } { #2 }
}

• Thank you for this suggestion. What are the advantages of this method ? With my proposal I have to define a global variable. That's all I can see. – Luc Armand May 17 at 13:07
• @LucArmand With my suggestion you have a sort of namespace for that kind of variables and, as I mentioned, it's easier to add items to the lists. And you have a clearer type distinction: a macro is just a macro, here you have instead a clist to begin with. – egreg May 17 at 13:11
• @LucArmand much as I hate to suggest that you give the tick to egreg rather than me, if you declare your variable types this way expl3 knows what expansions are needed and does the right thing. with my o (expand once), has the advantage with working with your input, but it always expands, so \myFilter gets expanded once which is what you want but so does the c in conversion,longueur. Expanding c is harmless but with more complicated inputs prematurely expanding things can lead to difficult to debug errors just as in your original example not expanding things can lead to errors. – David Carlisle May 17 at 13:23
• @egreg,@David Carlisle: thank you both. I will follow your advice David Carlisle :). – Luc Armand May 17 at 21:10

You need to expand the argument to get a list to iterate over

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{expl3}

\ExplSyntaxOn
\cs_generate_variant:Nn\clist_map_inline:nn{o}
\NewDocumentCommand{\makeenumerate}{ m }
{
\begin{enumerate}

\clist_map_inline:on { #1 } { \item \fbox{##1} }
\end{enumerate}
}
\ExplSyntaxOff

\newcommand{\myFilter}{conversion,longueur}

\begin{document}

\makeenumerate{\myFilter}

\end{document}

• It works perfectly, thank you! – Luc Armand May 17 at 13:08