TeX - LaTeX Asked on April 5, 2021
I have narrowed my problem to the next oversimplified token list (there are much more tokens that I do not know in advance)
tl_set:Nn l_tmpa_tl { myFoo myBar { myBaz } }
where for example
cs_set:Npn myFoo { Foo }
cs_set:Npn myBar { Bar }
cs_set:Npn myBaz { Baz }
I want to expand only myBar
and myBaz
and leave myFoo unexpanded to turn l_tmpa_tl
into
myFoo Bar { Baz }
To expand only myBar
, I can use a variant of tl_replace_once:Nnn
. Here is my code snippet
tl_set:Nx l_tmpb_tl { myBar }
cs_generate_variant:Nn tl_replace_once:Nnn { NnV }
tl_replace_once:NnV l_tmpa_tl { myBar } l_tmpb_tl
the result is actually
myFoo Bar { myBaz }
But how can I expand myBaz
while it is inside a group ?
Some kind of deep replace would help, or at least a mean to create the token list { Baz }
from only myBaz
.
Given your final comment that you can group the initial unexpanded tokens, it seems you only need consider three terms. This shows a log of
> l_tmpa_tl=macro:
->{myFoo myFoo myFoo }myBar {myBaz }.
l.11 showl_tmpa_tl
?
> l_tmpb_tl=long macro:
->{myFoo myFoo myFoo }Bar{Baz}.
l.20 showl_tmpb_tl
If you don't want the first tokens grouped in the final output you can use
cs_set:Npnzz_aux:NNn#1#2#3{exp_not:n{#1}#2{#3}}
But the output above is generated with
documentclass{article}
begin{document}
ExplSyntaxOn
cs_set:Npn myFoo { Foo }
cs_set:Npn myBar { Bar }
cs_set:Npn myBaz { Baz }
tl_set:Nn l_tmpa_tl { {myFoomyFoomyFoo} myBar { myBaz } }
showl_tmpa_tl
cs_set:Npnzz_aux:NNn#1#2#3{{exp_not:n{#1}}#2{#3}}
cs_set:Npnzz_expand:NN#1#2{
cs_set:Npx#2{exp_after:wNzz_aux:NNn#1}
}
zz_expand:NN l_tmpa_tl l_tmpb_tl
showl_tmpb_tl
ExplSyntaxOff
end{document}
Answered by David Carlisle on April 5, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP