Combine `map` and `use` expl3 macros

Clash Royale CLAN TAG#URR8PPP
I'm trying to build a macro
that processes a comma-separated-list of elements
so that:
MapAndUsea,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:
documentclassstandalone
usepackageexpl3
usepackagexparse
ExplSyntaxOn
NewDocumentCommandMapAndUse 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
begindocument
MapAndUsea,b,c
enddocument
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 theseq_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, andseq_map*cannot be expanded this way into another
"variable".UseMapa,b,cwith a 2-stages processing: does not work as expected
sinceMapa,b,cremains 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?
macros expl3 comma-separated-list mapping seq
add a comment |
I'm trying to build a macro
that processes a comma-separated-list of elements
so that:
MapAndUsea,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:
documentclassstandalone
usepackageexpl3
usepackagexparse
ExplSyntaxOn
NewDocumentCommandMapAndUse 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
begindocument
MapAndUsea,b,c
enddocument
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 theseq_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, andseq_map*cannot be expanded this way into another
"variable".UseMapa,b,cwith a 2-stages processing: does not work as expected
sinceMapa,b,cremains 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?
macros expl3 comma-separated-list mapping seq
add a comment |
I'm trying to build a macro
that processes a comma-separated-list of elements
so that:
MapAndUsea,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:
documentclassstandalone
usepackageexpl3
usepackagexparse
ExplSyntaxOn
NewDocumentCommandMapAndUse 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
begindocument
MapAndUsea,b,c
enddocument
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 theseq_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, andseq_map*cannot be expanded this way into another
"variable".UseMapa,b,cwith a 2-stages processing: does not work as expected
sinceMapa,b,cremains 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?
macros expl3 comma-separated-list mapping seq
I'm trying to build a macro
that processes a comma-separated-list of elements
so that:
MapAndUsea,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:
documentclassstandalone
usepackageexpl3
usepackagexparse
ExplSyntaxOn
NewDocumentCommandMapAndUse 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
begindocument
MapAndUsea,b,c
enddocument
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 theseq_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, andseq_map*cannot be expanded this way into another
"variable".UseMapa,b,cwith a 2-stages processing: does not work as expected
sinceMapa,b,cremains 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?
macros expl3 comma-separated-list mapping seq
macros expl3 comma-separated-list mapping seq
asked Feb 16 at 12:07
iago-litoiago-lito
682513
682513
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can use two sequences; first apply the mapping to get the “adorned” items, then use them.
documentclassarticle
usepackageexpl3
usepackagexparse
ExplSyntaxOn
seq_new:N l__iagolito_in_seq
seq_new:N l__iagolito_out_seq
NewDocumentCommandMapAndUse m
seq_set_from_clist:Nn l__iagolito_in_seq #1
seq_set_map:NNn l__iagolito_out_seq l__iagolito_in_seq (exp_not:n ##1 )
seq_use:Nn l__iagolito_out_seq ~--~
ExplSyntaxOff
begindocument
MapAndUsea,b,c
enddocument
An extended version where you can specify how to adorn the items and what to use between them:
documentclassarticle
usepackageexpl3
usepackagexparse
ExplSyntaxOn
seq_new:N l__iagolito_in_seq
seq_new:N l__iagolito_out_seq
NewDocumentCommandMapAndUse mmm
cs_set_protected:Nn __iagolito_mapanduse:n #2
seq_set_from_clist:Nn l__iagolito_in_seq #1
seq_set_map:NNn l__iagolito_out_seq l__iagolito_in_seq
__iagolito_mapanduse:n exp_not:n ##1
seq_use:Nn l__iagolito_out_seq #3
ExplSyntaxOff
begindocument
MapAndUsea,b,c(#1) --
enddocument

2
Awesome, cheers :) I was missingseq_set_mapandexp_not. It turns out the second one was actually the one I was trying to build :)
– iago-lito
Feb 16 at 12:21
MapAndUsedoes not work withincaptionin 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 usingsavebox.
– iago-lito
Feb 18 at 9:17
1
@iago-lito The genericMapAndUseshould be employed for defining semantic macros rather than explicitly. DoNewDocumentCommandparendashmMapAndUse#1(##1) --and useparendasha,b,c.
– egreg
Feb 18 at 9:27
This is what I actually did but the error was spat by the very semantic macro. My mistake was to define the semantic macro withnewcommandinstead ofNewDocumentCommand.. so your version does work :)
– iago-lito
Feb 18 at 9:37
1
@iago-lito Always remember that the argument tocaptionis a moving argument and that fragile commands need to be protected or made robust at the outset (whichNewDocumentCommanddoes).
– egreg
Feb 18 at 9:46
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f475170%2fcombine-map-and-use-expl3-macros%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use two sequences; first apply the mapping to get the “adorned” items, then use them.
documentclassarticle
usepackageexpl3
usepackagexparse
ExplSyntaxOn
seq_new:N l__iagolito_in_seq
seq_new:N l__iagolito_out_seq
NewDocumentCommandMapAndUse m
seq_set_from_clist:Nn l__iagolito_in_seq #1
seq_set_map:NNn l__iagolito_out_seq l__iagolito_in_seq (exp_not:n ##1 )
seq_use:Nn l__iagolito_out_seq ~--~
ExplSyntaxOff
begindocument
MapAndUsea,b,c
enddocument
An extended version where you can specify how to adorn the items and what to use between them:
documentclassarticle
usepackageexpl3
usepackagexparse
ExplSyntaxOn
seq_new:N l__iagolito_in_seq
seq_new:N l__iagolito_out_seq
NewDocumentCommandMapAndUse mmm
cs_set_protected:Nn __iagolito_mapanduse:n #2
seq_set_from_clist:Nn l__iagolito_in_seq #1
seq_set_map:NNn l__iagolito_out_seq l__iagolito_in_seq
__iagolito_mapanduse:n exp_not:n ##1
seq_use:Nn l__iagolito_out_seq #3
ExplSyntaxOff
begindocument
MapAndUsea,b,c(#1) --
enddocument

2
Awesome, cheers :) I was missingseq_set_mapandexp_not. It turns out the second one was actually the one I was trying to build :)
– iago-lito
Feb 16 at 12:21
MapAndUsedoes not work withincaptionin 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 usingsavebox.
– iago-lito
Feb 18 at 9:17
1
@iago-lito The genericMapAndUseshould be employed for defining semantic macros rather than explicitly. DoNewDocumentCommandparendashmMapAndUse#1(##1) --and useparendasha,b,c.
– egreg
Feb 18 at 9:27
This is what I actually did but the error was spat by the very semantic macro. My mistake was to define the semantic macro withnewcommandinstead ofNewDocumentCommand.. so your version does work :)
– iago-lito
Feb 18 at 9:37
1
@iago-lito Always remember that the argument tocaptionis a moving argument and that fragile commands need to be protected or made robust at the outset (whichNewDocumentCommanddoes).
– egreg
Feb 18 at 9:46
add a comment |
You can use two sequences; first apply the mapping to get the “adorned” items, then use them.
documentclassarticle
usepackageexpl3
usepackagexparse
ExplSyntaxOn
seq_new:N l__iagolito_in_seq
seq_new:N l__iagolito_out_seq
NewDocumentCommandMapAndUse m
seq_set_from_clist:Nn l__iagolito_in_seq #1
seq_set_map:NNn l__iagolito_out_seq l__iagolito_in_seq (exp_not:n ##1 )
seq_use:Nn l__iagolito_out_seq ~--~
ExplSyntaxOff
begindocument
MapAndUsea,b,c
enddocument
An extended version where you can specify how to adorn the items and what to use between them:
documentclassarticle
usepackageexpl3
usepackagexparse
ExplSyntaxOn
seq_new:N l__iagolito_in_seq
seq_new:N l__iagolito_out_seq
NewDocumentCommandMapAndUse mmm
cs_set_protected:Nn __iagolito_mapanduse:n #2
seq_set_from_clist:Nn l__iagolito_in_seq #1
seq_set_map:NNn l__iagolito_out_seq l__iagolito_in_seq
__iagolito_mapanduse:n exp_not:n ##1
seq_use:Nn l__iagolito_out_seq #3
ExplSyntaxOff
begindocument
MapAndUsea,b,c(#1) --
enddocument

2
Awesome, cheers :) I was missingseq_set_mapandexp_not. It turns out the second one was actually the one I was trying to build :)
– iago-lito
Feb 16 at 12:21
MapAndUsedoes not work withincaptionin 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 usingsavebox.
– iago-lito
Feb 18 at 9:17
1
@iago-lito The genericMapAndUseshould be employed for defining semantic macros rather than explicitly. DoNewDocumentCommandparendashmMapAndUse#1(##1) --and useparendasha,b,c.
– egreg
Feb 18 at 9:27
This is what I actually did but the error was spat by the very semantic macro. My mistake was to define the semantic macro withnewcommandinstead ofNewDocumentCommand.. so your version does work :)
– iago-lito
Feb 18 at 9:37
1
@iago-lito Always remember that the argument tocaptionis a moving argument and that fragile commands need to be protected or made robust at the outset (whichNewDocumentCommanddoes).
– egreg
Feb 18 at 9:46
add a comment |
You can use two sequences; first apply the mapping to get the “adorned” items, then use them.
documentclassarticle
usepackageexpl3
usepackagexparse
ExplSyntaxOn
seq_new:N l__iagolito_in_seq
seq_new:N l__iagolito_out_seq
NewDocumentCommandMapAndUse m
seq_set_from_clist:Nn l__iagolito_in_seq #1
seq_set_map:NNn l__iagolito_out_seq l__iagolito_in_seq (exp_not:n ##1 )
seq_use:Nn l__iagolito_out_seq ~--~
ExplSyntaxOff
begindocument
MapAndUsea,b,c
enddocument
An extended version where you can specify how to adorn the items and what to use between them:
documentclassarticle
usepackageexpl3
usepackagexparse
ExplSyntaxOn
seq_new:N l__iagolito_in_seq
seq_new:N l__iagolito_out_seq
NewDocumentCommandMapAndUse mmm
cs_set_protected:Nn __iagolito_mapanduse:n #2
seq_set_from_clist:Nn l__iagolito_in_seq #1
seq_set_map:NNn l__iagolito_out_seq l__iagolito_in_seq
__iagolito_mapanduse:n exp_not:n ##1
seq_use:Nn l__iagolito_out_seq #3
ExplSyntaxOff
begindocument
MapAndUsea,b,c(#1) --
enddocument

You can use two sequences; first apply the mapping to get the “adorned” items, then use them.
documentclassarticle
usepackageexpl3
usepackagexparse
ExplSyntaxOn
seq_new:N l__iagolito_in_seq
seq_new:N l__iagolito_out_seq
NewDocumentCommandMapAndUse m
seq_set_from_clist:Nn l__iagolito_in_seq #1
seq_set_map:NNn l__iagolito_out_seq l__iagolito_in_seq (exp_not:n ##1 )
seq_use:Nn l__iagolito_out_seq ~--~
ExplSyntaxOff
begindocument
MapAndUsea,b,c
enddocument
An extended version where you can specify how to adorn the items and what to use between them:
documentclassarticle
usepackageexpl3
usepackagexparse
ExplSyntaxOn
seq_new:N l__iagolito_in_seq
seq_new:N l__iagolito_out_seq
NewDocumentCommandMapAndUse mmm
cs_set_protected:Nn __iagolito_mapanduse:n #2
seq_set_from_clist:Nn l__iagolito_in_seq #1
seq_set_map:NNn l__iagolito_out_seq l__iagolito_in_seq
__iagolito_mapanduse:n exp_not:n ##1
seq_use:Nn l__iagolito_out_seq #3
ExplSyntaxOff
begindocument
MapAndUsea,b,c(#1) --
enddocument

answered Feb 16 at 12:14
egregegreg
726k8819193226
726k8819193226
2
Awesome, cheers :) I was missingseq_set_mapandexp_not. It turns out the second one was actually the one I was trying to build :)
– iago-lito
Feb 16 at 12:21
MapAndUsedoes not work withincaptionin 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 usingsavebox.
– iago-lito
Feb 18 at 9:17
1
@iago-lito The genericMapAndUseshould be employed for defining semantic macros rather than explicitly. DoNewDocumentCommandparendashmMapAndUse#1(##1) --and useparendasha,b,c.
– egreg
Feb 18 at 9:27
This is what I actually did but the error was spat by the very semantic macro. My mistake was to define the semantic macro withnewcommandinstead ofNewDocumentCommand.. so your version does work :)
– iago-lito
Feb 18 at 9:37
1
@iago-lito Always remember that the argument tocaptionis a moving argument and that fragile commands need to be protected or made robust at the outset (whichNewDocumentCommanddoes).
– egreg
Feb 18 at 9:46
add a comment |
2
Awesome, cheers :) I was missingseq_set_mapandexp_not. It turns out the second one was actually the one I was trying to build :)
– iago-lito
Feb 16 at 12:21
MapAndUsedoes not work withincaptionin 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 usingsavebox.
– iago-lito
Feb 18 at 9:17
1
@iago-lito The genericMapAndUseshould be employed for defining semantic macros rather than explicitly. DoNewDocumentCommandparendashmMapAndUse#1(##1) --and useparendasha,b,c.
– egreg
Feb 18 at 9:27
This is what I actually did but the error was spat by the very semantic macro. My mistake was to define the semantic macro withnewcommandinstead ofNewDocumentCommand.. so your version does work :)
– iago-lito
Feb 18 at 9:37
1
@iago-lito Always remember that the argument tocaptionis a moving argument and that fragile commands need to be protected or made robust at the outset (whichNewDocumentCommanddoes).
– egreg
Feb 18 at 9:46
2
2
Awesome, cheers :) I was missing
seq_set_map and exp_not. It turns out the second one was actually the one I was trying to build :)– iago-lito
Feb 16 at 12:21
Awesome, cheers :) I was missing
seq_set_map and exp_not. It turns out the second one was actually the one I was trying to build :)– iago-lito
Feb 16 at 12:21
MapAndUse does not work within caption in a figure environment, 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 at 9:17
MapAndUse does not work within caption in a figure environment, 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 at 9:17
1
1
@iago-lito The generic
MapAndUse should be employed for defining semantic macros rather than explicitly. Do NewDocumentCommandparendashmMapAndUse#1(##1) -- and use parendasha,b,c.– egreg
Feb 18 at 9:27
@iago-lito The generic
MapAndUse should be employed for defining semantic macros rather than explicitly. Do NewDocumentCommandparendashmMapAndUse#1(##1) -- and use parendasha,b,c.– egreg
Feb 18 at 9:27
This is what I actually did but the error was spat by the very semantic macro. My mistake was to define the semantic macro with
newcommand instead of NewDocumentCommand.. so your version does work :)– iago-lito
Feb 18 at 9:37
This is what I actually did but the error was spat by the very semantic macro. My mistake was to define the semantic macro with
newcommand instead of NewDocumentCommand.. so your version does work :)– iago-lito
Feb 18 at 9:37
1
1
@iago-lito Always remember that the argument to
caption is a moving argument and that fragile commands need to be protected or made robust at the outset (which NewDocumentCommand does).– egreg
Feb 18 at 9:46
@iago-lito Always remember that the argument to
caption is a moving argument and that fragile commands need to be protected or made robust at the outset (which NewDocumentCommand does).– egreg
Feb 18 at 9:46
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f475170%2fcombine-map-and-use-expl3-macros%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown