2

I'm trying to \SplitList / \ProcessList a clist set in a wrapper command's argument as the value of a key.

Unfortunately, it seems that the original command (\mycmd below) doesn't recognize the input it receives as an actual list, and instead treats it as just one "item" (see contents above the horizontal rule in the output).

I'm sorry if I'm just being clumsy somehow, but any help would be much appreciated.

\documentclass{article}

\usepackage{xparse}

\NewDocumentCommand{\mycmd}{ >{\SplitList{,}} m }{
    \ProcessList{#1}{\myprocessline}
}
\NewDocumentCommand{\myprocessline}{m}{
    \noindent #1, and\par
}
\ExplSyntaxOn
\keys_define:nn{mykeys}{
    mylist .clist_set:N = \l_mykeys_mylist_tl
}
\NewDocumentCommand{\wrapper}{ O{} }{
    \keys_set:nn{mykeys}{#1}
    \mycmd{\l_mykeys_mylist_tl}
}
\ExplSyntaxOff

\begin{document}

\wrapper[mylist={line one, line two, line three}]

\noindent\hrulefill

\mycmd{line one, line two, line three}

\end{document}

screenshot of output

2

You are not passing a comma separated list, but something that contains a comma separated list.

\documentclass{article}

\usepackage{xparse}

\NewDocumentCommand{\mycmd}{ >{\SplitList{,}} m }{%
    \ProcessList{#1}{\myprocessline}%
}
\NewDocumentCommand{\myprocessline}{m}{%
    \noindent #1, and\par
}
\ExplSyntaxOn
\keys_define:nn{mykeys}
  {
    mylist .clist_set:N = \l_mykeys_mylist_clist
  }
\NewDocumentCommand{\wrapper}{ O{} }
  {
    \keys_set:nn{mykeys}{#1}
    \exp_args:NV \mycmd \l_mykeys_mylist_clist
  }
\ExplSyntaxOff

\begin{document}

\wrapper[mylist={line one, line two, line three}]

\noindent\hrulefill

\mycmd{line one, line two, line three}

\end{document}

enter image description here

However, I'd use a different approach, because \SplitList is only meant for “simple” cases.

\documentclass{article}

\usepackage{xparse}

\ExplSyntaxOn

\NewDocumentCommand{\mycmd}{ m }
  {
    \steve_mycmd_main:n { #1 }
  }

\NewDocumentCommand{\wrapper}{ O{} }
  {
    \keys_set:nn{mykeys}{#1}
    \steve_mycmd_main:V \l_mykeys_mylist_clist
  }

\cs_new_protected:Nn \steve_mycmd_main:n
  {
    \clist_map_function:nN { #1 } \steve_mycmd_processline:n
  }
\cs_generate_variant:Nn \steve_mycmd_main:n { V }

\cs_new:Nn \steve_mycmd_processline:n
  {
    \noindent #1, ~ and\par
  }

\keys_define:nn{mykeys}
  {
    mylist .clist_set:N = \l_mykeys_mylist_clist
  }
\ExplSyntaxOff

\begin{document}

\wrapper[mylist={line one, line two, line three}]

\noindent\hrulefill

\mycmd{line one, line two, line three}

\end{document}
1

You need to expand the arguments of \mycmd in your \wrapper macro:

Use

\exp_args:Nx \mycmd {\l_mykeys_mylist_tl}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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