Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to convert a space separated list of items, given as argument to a function, into a clist variable in order to iterate over them. However, I am not able to create a usable clist variable as the following code example demonstrates. \clist_map_inline:Nn always takes the whole list instead of separating the elements. What am I doing wrong?

\documentclass{minimal}
\usepackage{expl3}

\ExplSyntaxOn
\cs_new:Nn\parselist:n{
  \tl_set:Nx\l_csv_tl{#1}
  \tl_replace_all:Nnn\l_csv_tl{~}{,}
  \clist_set:Nx\l_csv_clist\l_csv_tl
  \clist_map_inline:Nn\l_csv_clist{
    \noindent Name:~#1\par
  }
}
\ExplSyntaxOff

\begin{document}
\def\csv{fred jane albert}
\ExplSyntaxOn
  \parselist:n\csv
  \parselist:n{john~peter~linda}
\ExplSyntaxOff
\end{document}
share|improve this question
1  
You must use Name:~##1. With #1 you are getting the outer argument. –  Ulrike Fischer Dec 2 '11 at 11:41
1  
Unless you need a clist for other reasons, I'd use a sequence and \seq_set_split:Nnn here. –  Joseph Wright Dec 2 '11 at 12:43
    
Also, you are slightly mis-behaving here with the arg spec. I'd say your first use of \parselist:n should be either a V or N function (little in it here). –  Joseph Wright Dec 2 '11 at 12:44
    
@Joseph Wright: Thanks for mentioning the sequence data type. I like the suggested \seq_set_split:Nnn very much, but is it stable enough to be used in a public package? –  AlexG Dec 2 '11 at 13:21
    
@AlexanderGrahn One for LaTeX-L! I'd say that if we add something 'experimental', what will get it made 'non-experimental' is good use cases. So give feedback on what you use and we can move them. I'll alter the status of \seq_set_split:Nnn over the next few days: it's definitely useful. –  Joseph Wright Dec 2 '11 at 13:58

1 Answer 1

up vote 4 down vote accepted

I found out the error myself. Using ##1 in the function body of \clist_map_inline:Nn does the trick. Otherwise the original argument as given to \parselist:n is used.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.