# Processing separated list of separated lists

Is it possible to create function foo that takes list of arguments and this argument is also a list, e.g. to require the following semantics \foo[x:1,z,y:2], i.e. it takes three comma separated arguments x:1, y:2 and z, where x:1 is parsed into two arguments passing to another function inside foo and 1 is optional argument?

For example, suppose function \textoverset defined as follows:

    \NewDocumentCommand{\textoverset}{ m m }{%
\tikz[baseline=(Root.base)]{%
\node[inner sep=0pt,
outer sep=0pt,
label={#3}] (Root) {#2};
}%
}


Suppose textoverset is utilised inside foo, so invoking \underline{\foo[x:1,z,y:2]} would give result depicted in the attachment.

You can do a three stage process: in the first stage you split at commas; the second stage splits each item at the colon and the third stage calls \textoverset.

\documentclass{article}
\usepackage{tikz,xparse}

\NewDocumentCommand{\textoverset}{ m m }{%
\tikz[baseline=(Root.base)]{%
\node[
inner sep=0pt,
outer sep=0pt,
label={#2},
] (Root) {#1};%
}%
}

\NewDocumentCommand{\foo}{ >{\SplitList{,}}m }{\ProcessList{#1}{\fooaux}}

\NewDocumentCommand{\fooaux}{ >{\SplitArgument{1}{:}}m } {\fooauxa#1}

\NewDocumentCommand{\fooauxa}{mm}{%
\IfNoValueTF{#2}{\textoverset{#1}{}}{\textoverset{#1}{#2}}%
}

\begin{document}

\textoverset{x}{1}\textoverset{y}{}\textoverset{z}{2}

\foo{x:1,y,z:2}

\end{document}


• Thank is great, @egreg. I implicitly meant that under the x could be word of arbitrary length, so in this case all words are stuck together. Could you, please, suggest how to handle this? P.S. You answers do meet question conditions, which means the answer should be accepted, but I found out that I implicitly meant slightly different. What should I do in this case — accept answer and create another question, edit question and wait for other solutions? – robur Jul 5 at 15:05
• @robur Sorry, but I don't understand the new constraints. Changing the question as to invalidate the answer is not in the spirit of the site. – egreg Jul 5 at 15:06
• okay, constraints I am talking about may become clear if to typeset the following commands: \textoverset{worm}{1} \textoverset{yummy}{} \textoverset{zoo}{2} and \foo{worm:1,yummy,zoo:2}. In first case there is spacing between lower words, in the second — there is no. P.S. Got you. – robur Jul 5 at 15:16