Preserving spaces when scannig `tl` variables into a sequence using `seq_set_split`
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
As stated in the interface3 document (Part IX, 1. Creating and initializing sequences) seq_set_split:
does not preserve spaces. Wishing to scan the text contained in a _tl variable into a sequence item by item for further processing (to be parsed for example) it would be advantageous to have spaces preserved. The MWE demonstrates that this can be achieved by introducing hard spaces
, but is there a way to make do without the ~
s?
documentclassarticle
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]expl3
usepackagexparse
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
seq_set_split:NnV l_rn_auxOne_seq l_rn_auxOne_tl
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,\
% myExperminent
ExplSyntaxOff
%-----------------------
begindocument
verb+myScanTextThe quick brown fox jumps over the lazy dog.+\
myScanTextThe quick brown fox jumps over the lazy dog.
verb+myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.+\
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
expl3
add a comment |
up vote
2
down vote
favorite
As stated in the interface3 document (Part IX, 1. Creating and initializing sequences) seq_set_split:
does not preserve spaces. Wishing to scan the text contained in a _tl variable into a sequence item by item for further processing (to be parsed for example) it would be advantageous to have spaces preserved. The MWE demonstrates that this can be achieved by introducing hard spaces
, but is there a way to make do without the ~
s?
documentclassarticle
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]expl3
usepackagexparse
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
seq_set_split:NnV l_rn_auxOne_seq l_rn_auxOne_tl
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,\
% myExperminent
ExplSyntaxOff
%-----------------------
begindocument
verb+myScanTextThe quick brown fox jumps over the lazy dog.+\
myScanTextThe quick brown fox jumps over the lazy dog.
verb+myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.+\
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
expl3
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
As stated in the interface3 document (Part IX, 1. Creating and initializing sequences) seq_set_split:
does not preserve spaces. Wishing to scan the text contained in a _tl variable into a sequence item by item for further processing (to be parsed for example) it would be advantageous to have spaces preserved. The MWE demonstrates that this can be achieved by introducing hard spaces
, but is there a way to make do without the ~
s?
documentclassarticle
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]expl3
usepackagexparse
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
seq_set_split:NnV l_rn_auxOne_seq l_rn_auxOne_tl
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,\
% myExperminent
ExplSyntaxOff
%-----------------------
begindocument
verb+myScanTextThe quick brown fox jumps over the lazy dog.+\
myScanTextThe quick brown fox jumps over the lazy dog.
verb+myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.+\
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
expl3
As stated in the interface3 document (Part IX, 1. Creating and initializing sequences) seq_set_split:
does not preserve spaces. Wishing to scan the text contained in a _tl variable into a sequence item by item for further processing (to be parsed for example) it would be advantageous to have spaces preserved. The MWE demonstrates that this can be achieved by introducing hard spaces
, but is there a way to make do without the ~
s?
documentclassarticle
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]expl3
usepackagexparse
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
seq_set_split:NnV l_rn_auxOne_seq l_rn_auxOne_tl
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,\
% myExperminent
ExplSyntaxOff
%-----------------------
begindocument
verb+myScanTextThe quick brown fox jumps over the lazy dog.+\
myScanTextThe quick brown fox jumps over the lazy dog.
verb+myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.+\
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
expl3
expl3
asked 8 hours ago
Reinhard Neuwirth
1,44511321
1,44511321
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
2
down vote
accepted
Use a slower routine first splitting at spaces.
documentclassarticle
usepackage[margin=1cm]geometry
usepackagexparse
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
tl_new:N l_rn_auxTwo_tl
seq_new:N l_rn_auxOne_seq
seq_new:N l_rn_auxTwo_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
seq_clear:N l_rn_auxOne_seq
% split at spaces
seq_set_split:Nnn l_rn_auxTwo_seq ~ #1
% the first item is special, pop it out and split it
seq_pop_left:NN l_rn_auxTwo_seq l_rn_auxTwo_tl
tl_map_function:NN l_rn_auxTwo_tl __rn_add:n
% now do the other items, reinserting the space before them
seq_map_inline:Nn l_rn_auxTwo_seq
__rn_add:n ~
tl_map_function:nN ##1 __rn_add:n
% print the data
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,
cs_new_protected:Nn __rn_add:n
seq_put_right:Nn l_rn_auxOne_seq #1
ExplSyntaxOff
%-----------------------
begindocument
setlengthparindent0pt % just for the example
myScanTextThe quick brown fox jumps over the lazy dog.
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
Alternative method: first replace spaces with a private token and then split with tl_map_function:NN
documentclassarticle
usepackage[margin=1cm]geometry
usepackagexparse
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
seq_clear:N l_rn_auxOne_seq
tl_set:Nn l_rn_auxOne_tl #1
tl_replace_all:Nnn l_rn_auxOne_tl ~ __rn_space:
tl_map_function:NN l_rn_auxOne_tl __rn_add:n
% print the data
textbfinput:~#1\
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,
cs_new_protected:Nn __rn_add:n
tl_if_eq:nnTF #1 __rn_space:
seq_put_right:Nn l_rn_auxOne_seq ~
seq_put_right:Nn l_rn_auxOne_seq #1
cs_new_protected:Nn __rn_space:
ExplSyntaxOff
%-----------------------
begindocument
setlengthparindent0pt % just for the example
myScanTextThe quick brown fox jumps over the lazy dog.
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
add a comment |
up vote
2
down vote
You could use str_map_inline:Nn
and append to the seq
. The problem is that catcodes are all 12 then.
documentclassarticle
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]expl3
usepackagexparse
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
seq_clear:N l_rn_auxOne_seq
str_map_inline:Nn l_rn_auxOne_tl seq_put_right:Nn l_rn_auxOne_seq ##1
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,\
% myExperminent
ExplSyntaxOff
%-----------------------
begindocument
verb+myScanTextThe quick brown fox jumps over the lazy dog.+\
myScanTextThe quick brown fox jumps over the lazy dog.
verb+myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.+\
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
add a comment |
up vote
1
down vote
You could pre-process the input using regex_replace_all:nnN
to replace all spaces with space
. (I first tried replacing spaces with ~
and ~
but this did not work so well.) Doing this your MWE produces:
Here is the code:
documentclassarticle
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]expl3
usepackagexparse
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
regex_replace_all:nnN s+ cspace l_rn_auxOne_tl
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
seq_set_split:NnV l_rn_auxOne_seq l_rn_auxOne_tl
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,\
% myExperminent
ExplSyntaxOff
%-----------------------
begindocument
verb+myScanTextThe quick brown fox jumps over the lazy dog.+\
myScanTextThe quick brown fox jumps over the lazy dog.
verb+myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.+\
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
Note that this replaces repeated spaces with a single space
, which I'm guessing is probably what you'd really want.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Use a slower routine first splitting at spaces.
documentclassarticle
usepackage[margin=1cm]geometry
usepackagexparse
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
tl_new:N l_rn_auxTwo_tl
seq_new:N l_rn_auxOne_seq
seq_new:N l_rn_auxTwo_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
seq_clear:N l_rn_auxOne_seq
% split at spaces
seq_set_split:Nnn l_rn_auxTwo_seq ~ #1
% the first item is special, pop it out and split it
seq_pop_left:NN l_rn_auxTwo_seq l_rn_auxTwo_tl
tl_map_function:NN l_rn_auxTwo_tl __rn_add:n
% now do the other items, reinserting the space before them
seq_map_inline:Nn l_rn_auxTwo_seq
__rn_add:n ~
tl_map_function:nN ##1 __rn_add:n
% print the data
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,
cs_new_protected:Nn __rn_add:n
seq_put_right:Nn l_rn_auxOne_seq #1
ExplSyntaxOff
%-----------------------
begindocument
setlengthparindent0pt % just for the example
myScanTextThe quick brown fox jumps over the lazy dog.
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
Alternative method: first replace spaces with a private token and then split with tl_map_function:NN
documentclassarticle
usepackage[margin=1cm]geometry
usepackagexparse
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
seq_clear:N l_rn_auxOne_seq
tl_set:Nn l_rn_auxOne_tl #1
tl_replace_all:Nnn l_rn_auxOne_tl ~ __rn_space:
tl_map_function:NN l_rn_auxOne_tl __rn_add:n
% print the data
textbfinput:~#1\
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,
cs_new_protected:Nn __rn_add:n
tl_if_eq:nnTF #1 __rn_space:
seq_put_right:Nn l_rn_auxOne_seq ~
seq_put_right:Nn l_rn_auxOne_seq #1
cs_new_protected:Nn __rn_space:
ExplSyntaxOff
%-----------------------
begindocument
setlengthparindent0pt % just for the example
myScanTextThe quick brown fox jumps over the lazy dog.
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
add a comment |
up vote
2
down vote
accepted
Use a slower routine first splitting at spaces.
documentclassarticle
usepackage[margin=1cm]geometry
usepackagexparse
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
tl_new:N l_rn_auxTwo_tl
seq_new:N l_rn_auxOne_seq
seq_new:N l_rn_auxTwo_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
seq_clear:N l_rn_auxOne_seq
% split at spaces
seq_set_split:Nnn l_rn_auxTwo_seq ~ #1
% the first item is special, pop it out and split it
seq_pop_left:NN l_rn_auxTwo_seq l_rn_auxTwo_tl
tl_map_function:NN l_rn_auxTwo_tl __rn_add:n
% now do the other items, reinserting the space before them
seq_map_inline:Nn l_rn_auxTwo_seq
__rn_add:n ~
tl_map_function:nN ##1 __rn_add:n
% print the data
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,
cs_new_protected:Nn __rn_add:n
seq_put_right:Nn l_rn_auxOne_seq #1
ExplSyntaxOff
%-----------------------
begindocument
setlengthparindent0pt % just for the example
myScanTextThe quick brown fox jumps over the lazy dog.
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
Alternative method: first replace spaces with a private token and then split with tl_map_function:NN
documentclassarticle
usepackage[margin=1cm]geometry
usepackagexparse
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
seq_clear:N l_rn_auxOne_seq
tl_set:Nn l_rn_auxOne_tl #1
tl_replace_all:Nnn l_rn_auxOne_tl ~ __rn_space:
tl_map_function:NN l_rn_auxOne_tl __rn_add:n
% print the data
textbfinput:~#1\
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,
cs_new_protected:Nn __rn_add:n
tl_if_eq:nnTF #1 __rn_space:
seq_put_right:Nn l_rn_auxOne_seq ~
seq_put_right:Nn l_rn_auxOne_seq #1
cs_new_protected:Nn __rn_space:
ExplSyntaxOff
%-----------------------
begindocument
setlengthparindent0pt % just for the example
myScanTextThe quick brown fox jumps over the lazy dog.
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Use a slower routine first splitting at spaces.
documentclassarticle
usepackage[margin=1cm]geometry
usepackagexparse
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
tl_new:N l_rn_auxTwo_tl
seq_new:N l_rn_auxOne_seq
seq_new:N l_rn_auxTwo_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
seq_clear:N l_rn_auxOne_seq
% split at spaces
seq_set_split:Nnn l_rn_auxTwo_seq ~ #1
% the first item is special, pop it out and split it
seq_pop_left:NN l_rn_auxTwo_seq l_rn_auxTwo_tl
tl_map_function:NN l_rn_auxTwo_tl __rn_add:n
% now do the other items, reinserting the space before them
seq_map_inline:Nn l_rn_auxTwo_seq
__rn_add:n ~
tl_map_function:nN ##1 __rn_add:n
% print the data
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,
cs_new_protected:Nn __rn_add:n
seq_put_right:Nn l_rn_auxOne_seq #1
ExplSyntaxOff
%-----------------------
begindocument
setlengthparindent0pt % just for the example
myScanTextThe quick brown fox jumps over the lazy dog.
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
Alternative method: first replace spaces with a private token and then split with tl_map_function:NN
documentclassarticle
usepackage[margin=1cm]geometry
usepackagexparse
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
seq_clear:N l_rn_auxOne_seq
tl_set:Nn l_rn_auxOne_tl #1
tl_replace_all:Nnn l_rn_auxOne_tl ~ __rn_space:
tl_map_function:NN l_rn_auxOne_tl __rn_add:n
% print the data
textbfinput:~#1\
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,
cs_new_protected:Nn __rn_add:n
tl_if_eq:nnTF #1 __rn_space:
seq_put_right:Nn l_rn_auxOne_seq ~
seq_put_right:Nn l_rn_auxOne_seq #1
cs_new_protected:Nn __rn_space:
ExplSyntaxOff
%-----------------------
begindocument
setlengthparindent0pt % just for the example
myScanTextThe quick brown fox jumps over the lazy dog.
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
Use a slower routine first splitting at spaces.
documentclassarticle
usepackage[margin=1cm]geometry
usepackagexparse
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
tl_new:N l_rn_auxTwo_tl
seq_new:N l_rn_auxOne_seq
seq_new:N l_rn_auxTwo_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
seq_clear:N l_rn_auxOne_seq
% split at spaces
seq_set_split:Nnn l_rn_auxTwo_seq ~ #1
% the first item is special, pop it out and split it
seq_pop_left:NN l_rn_auxTwo_seq l_rn_auxTwo_tl
tl_map_function:NN l_rn_auxTwo_tl __rn_add:n
% now do the other items, reinserting the space before them
seq_map_inline:Nn l_rn_auxTwo_seq
__rn_add:n ~
tl_map_function:nN ##1 __rn_add:n
% print the data
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,
cs_new_protected:Nn __rn_add:n
seq_put_right:Nn l_rn_auxOne_seq #1
ExplSyntaxOff
%-----------------------
begindocument
setlengthparindent0pt % just for the example
myScanTextThe quick brown fox jumps over the lazy dog.
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
Alternative method: first replace spaces with a private token and then split with tl_map_function:NN
documentclassarticle
usepackage[margin=1cm]geometry
usepackagexparse
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
seq_clear:N l_rn_auxOne_seq
tl_set:Nn l_rn_auxOne_tl #1
tl_replace_all:Nnn l_rn_auxOne_tl ~ __rn_space:
tl_map_function:NN l_rn_auxOne_tl __rn_add:n
% print the data
textbfinput:~#1\
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,
cs_new_protected:Nn __rn_add:n
tl_if_eq:nnTF #1 __rn_space:
seq_put_right:Nn l_rn_auxOne_seq ~
seq_put_right:Nn l_rn_auxOne_seq #1
cs_new_protected:Nn __rn_space:
ExplSyntaxOff
%-----------------------
begindocument
setlengthparindent0pt % just for the example
myScanTextThe quick brown fox jumps over the lazy dog.
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
edited 6 hours ago
answered 7 hours ago
egreg
696k8518483111
696k8518483111
add a comment |
add a comment |
up vote
2
down vote
You could use str_map_inline:Nn
and append to the seq
. The problem is that catcodes are all 12 then.
documentclassarticle
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]expl3
usepackagexparse
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
seq_clear:N l_rn_auxOne_seq
str_map_inline:Nn l_rn_auxOne_tl seq_put_right:Nn l_rn_auxOne_seq ##1
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,\
% myExperminent
ExplSyntaxOff
%-----------------------
begindocument
verb+myScanTextThe quick brown fox jumps over the lazy dog.+\
myScanTextThe quick brown fox jumps over the lazy dog.
verb+myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.+\
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
add a comment |
up vote
2
down vote
You could use str_map_inline:Nn
and append to the seq
. The problem is that catcodes are all 12 then.
documentclassarticle
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]expl3
usepackagexparse
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
seq_clear:N l_rn_auxOne_seq
str_map_inline:Nn l_rn_auxOne_tl seq_put_right:Nn l_rn_auxOne_seq ##1
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,\
% myExperminent
ExplSyntaxOff
%-----------------------
begindocument
verb+myScanTextThe quick brown fox jumps over the lazy dog.+\
myScanTextThe quick brown fox jumps over the lazy dog.
verb+myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.+\
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
add a comment |
up vote
2
down vote
up vote
2
down vote
You could use str_map_inline:Nn
and append to the seq
. The problem is that catcodes are all 12 then.
documentclassarticle
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]expl3
usepackagexparse
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
seq_clear:N l_rn_auxOne_seq
str_map_inline:Nn l_rn_auxOne_tl seq_put_right:Nn l_rn_auxOne_seq ##1
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,\
% myExperminent
ExplSyntaxOff
%-----------------------
begindocument
verb+myScanTextThe quick brown fox jumps over the lazy dog.+\
myScanTextThe quick brown fox jumps over the lazy dog.
verb+myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.+\
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
You could use str_map_inline:Nn
and append to the seq
. The problem is that catcodes are all 12 then.
documentclassarticle
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]expl3
usepackagexparse
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
seq_clear:N l_rn_auxOne_seq
str_map_inline:Nn l_rn_auxOne_tl seq_put_right:Nn l_rn_auxOne_seq ##1
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,\
% myExperminent
ExplSyntaxOff
%-----------------------
begindocument
verb+myScanTextThe quick brown fox jumps over the lazy dog.+\
myScanTextThe quick brown fox jumps over the lazy dog.
verb+myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.+\
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
answered 7 hours ago
Henri Menke
66.5k7147255
66.5k7147255
add a comment |
add a comment |
up vote
1
down vote
You could pre-process the input using regex_replace_all:nnN
to replace all spaces with space
. (I first tried replacing spaces with ~
and ~
but this did not work so well.) Doing this your MWE produces:
Here is the code:
documentclassarticle
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]expl3
usepackagexparse
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
regex_replace_all:nnN s+ cspace l_rn_auxOne_tl
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
seq_set_split:NnV l_rn_auxOne_seq l_rn_auxOne_tl
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,\
% myExperminent
ExplSyntaxOff
%-----------------------
begindocument
verb+myScanTextThe quick brown fox jumps over the lazy dog.+\
myScanTextThe quick brown fox jumps over the lazy dog.
verb+myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.+\
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
Note that this replaces repeated spaces with a single space
, which I'm guessing is probably what you'd really want.
add a comment |
up vote
1
down vote
You could pre-process the input using regex_replace_all:nnN
to replace all spaces with space
. (I first tried replacing spaces with ~
and ~
but this did not work so well.) Doing this your MWE produces:
Here is the code:
documentclassarticle
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]expl3
usepackagexparse
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
regex_replace_all:nnN s+ cspace l_rn_auxOne_tl
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
seq_set_split:NnV l_rn_auxOne_seq l_rn_auxOne_tl
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,\
% myExperminent
ExplSyntaxOff
%-----------------------
begindocument
verb+myScanTextThe quick brown fox jumps over the lazy dog.+\
myScanTextThe quick brown fox jumps over the lazy dog.
verb+myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.+\
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
Note that this replaces repeated spaces with a single space
, which I'm guessing is probably what you'd really want.
add a comment |
up vote
1
down vote
up vote
1
down vote
You could pre-process the input using regex_replace_all:nnN
to replace all spaces with space
. (I first tried replacing spaces with ~
and ~
but this did not work so well.) Doing this your MWE produces:
Here is the code:
documentclassarticle
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]expl3
usepackagexparse
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
regex_replace_all:nnN s+ cspace l_rn_auxOne_tl
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
seq_set_split:NnV l_rn_auxOne_seq l_rn_auxOne_tl
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,\
% myExperminent
ExplSyntaxOff
%-----------------------
begindocument
verb+myScanTextThe quick brown fox jumps over the lazy dog.+\
myScanTextThe quick brown fox jumps over the lazy dog.
verb+myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.+\
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
Note that this replaces repeated spaces with a single space
, which I'm guessing is probably what you'd really want.
You could pre-process the input using regex_replace_all:nnN
to replace all spaces with space
. (I first tried replacing spaces with ~
and ~
but this did not work so well.) Doing this your MWE produces:
Here is the code:
documentclassarticle
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]expl3
usepackagexparse
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanTextm
tl_set:Nn l_rn_auxOne_tl #1
regex_replace_all:nnN s+ cspace l_rn_auxOne_tl
textbftl~variable:~tl_use:N l_rn_auxOne_tl\
seq_set_split:NnV l_rn_auxOne_seq l_rn_auxOne_tl
textbfseq~variable:~seq_use:Nn l_rn_auxOne_seq ,\
% myExperminent
ExplSyntaxOff
%-----------------------
begindocument
verb+myScanTextThe quick brown fox jumps over the lazy dog.+\
myScanTextThe quick brown fox jumps over the lazy dog.
verb+myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.+\
myScanTextThe~quick~brown~fox~jumps~over~the~lazy~dog.
enddocument
Note that this replaces repeated spaces with a single space
, which I'm guessing is probably what you'd really want.
answered 7 hours ago
Andrew
28.9k34177
28.9k34177
add a comment |
add a comment |
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f459519%2fpreserving-spaces-when-scannig-tl-variables-into-a-sequence-using-seq-set-sp%23new-answer', 'question_page');
);
Post as a guest
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
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
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