I'm trying to build a macro that processes a comma-separated-list of elements so that:
\MapAndUse{a,b,c}
would produce:
My first intuition is to use a expl3 combination
of \seq_map* to process each element in turn
(here, wrap into parentheses)
then \seq_use* to organize them around -- markers.
But this does not work as expected:
\documentclass{standalone}
\usepackage{expl3}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\MapAndUse}{ m }{%
\seq_set_from_clist:Nn \l_raw_seq {#1}
\seq_map_variable:NNn \l_raw_seq \i {(\i)}
% \seq_show:N \l_raw_seq
\seq_use:Nn \l_raw_seq {\ --\ }
}
\ExplSyntaxOff
\begin{document}
\MapAndUse{a,b,c}
\end{document}
Since it produces:
From what I understand:
- from the doc:
\seq_map_*macros directly expand to the input stream. - from
\seq_show:N \l_raw_seq: the sequence is not actually affected by the\seq_mapcommand (elements are not parenthesized)
The sequence \l_raw_seq contains the items (without outer braces):
> {a}
> {b}
> {c}.
How do I process each element "in place" with \seq_map* without having them
pushed to the input stream?
Naive tries:
\seq_set_from_clist:Nx \l_processed_seq {\seq_map_variable:NNn \l_raw_seq \i {,(\i)}}: does not compile in consistence with the doc: thisNxvariant does not exist, and\seq_map*cannot be expanded this way into another "variable".\Use{\Map{a,b,c}}with a 2-stages processing: does not work as expected since\Map{a,b,c}remains unexpanded.
Is there anything I've missed about expl3 logic there?
Is it possible to process my comma-separated input this way?
Are there alternatives or workarounds?



\seq_set_mapand\exp_not. It turns out the second one was actually the one I was trying to build :) – iago-lito Feb 16 '19 at 12:21\MapAndUsedoes not work within\captionin afigureenvironment, what could be wrong? The compiler spits! Illegal parameter number in definition of \reserved@a. <to be read again>I can work around this bug using\savebox. – iago-lito Feb 18 '19 at 09:17\MapAndUseshould be employed for defining semantic macros rather than explicitly. Do\NewDocumentCommand{\parendash}{m}{\MapAndUse{#1}{(##1)}{ -- }}and use\parendash{a,b,c}. – egreg Feb 18 '19 at 09:27\newcommandinstead of\NewDocumentCommand.. so your version does work :) – iago-lito Feb 18 '19 at 09:37\captionis a moving argument and that fragile commands need to be protected or made robust at the outset (which\NewDocumentCommanddoes). – egreg Feb 18 '19 at 09:46