Preserving spaces when scannig `tl` variables into a sequence using `seq_set_split`
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?
documentclass{article}
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]{expl3}
usepackage{xparse}
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
tl_set:Nn l_rn_auxOne_tl {#1}
textbf{tl~variable:}~tl_use:N l_rn_auxOne_tl\
seq_set_split:NnV l_rn_auxOne_seq {} l_rn_auxOne_tl
textbf{seq~variable:}~seq_use:Nn l_rn_auxOne_seq {,}\
} % myExperminent
ExplSyntaxOff
%-----------------------
begin{document}
verb+myScanText{The quick brown fox jumps over the lazy dog.}+\
myScanText{The quick brown fox jumps over the lazy dog.}
verb+myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}+\
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
expl3
add a comment |
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?
documentclass{article}
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]{expl3}
usepackage{xparse}
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
tl_set:Nn l_rn_auxOne_tl {#1}
textbf{tl~variable:}~tl_use:N l_rn_auxOne_tl\
seq_set_split:NnV l_rn_auxOne_seq {} l_rn_auxOne_tl
textbf{seq~variable:}~seq_use:Nn l_rn_auxOne_seq {,}\
} % myExperminent
ExplSyntaxOff
%-----------------------
begin{document}
verb+myScanText{The quick brown fox jumps over the lazy dog.}+\
myScanText{The quick brown fox jumps over the lazy dog.}
verb+myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}+\
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
expl3
add a comment |
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?
documentclass{article}
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]{expl3}
usepackage{xparse}
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
tl_set:Nn l_rn_auxOne_tl {#1}
textbf{tl~variable:}~tl_use:N l_rn_auxOne_tl\
seq_set_split:NnV l_rn_auxOne_seq {} l_rn_auxOne_tl
textbf{seq~variable:}~seq_use:Nn l_rn_auxOne_seq {,}\
} % myExperminent
ExplSyntaxOff
%-----------------------
begin{document}
verb+myScanText{The quick brown fox jumps over the lazy dog.}+\
myScanText{The quick brown fox jumps over the lazy dog.}
verb+myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}+\
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
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?
documentclass{article}
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]{expl3}
usepackage{xparse}
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
tl_set:Nn l_rn_auxOne_tl {#1}
textbf{tl~variable:}~tl_use:N l_rn_auxOne_tl\
seq_set_split:NnV l_rn_auxOne_seq {} l_rn_auxOne_tl
textbf{seq~variable:}~seq_use:Nn l_rn_auxOne_seq {,}\
} % myExperminent
ExplSyntaxOff
%-----------------------
begin{document}
verb+myScanText{The quick brown fox jumps over the lazy dog.}+\
myScanText{The quick brown fox jumps over the lazy dog.}
verb+myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}+\
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
expl3
expl3
asked Nov 11 '18 at 21:31
Reinhard Neuwirth
1,55111322
1,55111322
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Use a slower routine first splitting at spaces.
documentclass{article}
usepackage[margin=1cm]{geometry}
usepackage{xparse}
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
NewDocumentCommandmyScanText{m}
{
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
textbf{tl~variable:}~tl_use:N l_rn_auxOne_tl\
textbf{seq~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
%-----------------------
begin{document}
setlength{parindent}{0pt} % just for the example
myScanText{The quick brown fox jumps over the lazy dog.}
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
Alternative method: first replace spaces with a private token and then split with tl_map_function:NN
documentclass{article}
usepackage[margin=1cm]{geometry}
usepackage{xparse}
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
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
textbf{input:}~#1\
textbf{seq~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
%-----------------------
begin{document}
setlength{parindent}{0pt} % just for the example
myScanText{The quick brown fox jumps over the lazy dog.}
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
Whycs_new_protected:Nn __rn_space: {}
? This token should never be expanded anyway.
– Henri Menke
Nov 12 '18 at 6:17
@HenriMenke Because it should have a definition.
– egreg
Nov 12 '18 at 7:50
add a comment |
You could use str_map_inline:Nn
and append to the seq
. The problem is that catcodes are all 12 then.
documentclass{article}
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]{expl3}
usepackage{xparse}
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
tl_set:Nn l_rn_auxOne_tl {#1}
textbf{tl~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 } }
textbf{seq~variable:}~seq_use:Nn l_rn_auxOne_seq {,}\
} % myExperminent
ExplSyntaxOff
%-----------------------
begin{document}
verb+myScanText{The quick brown fox jumps over the lazy dog.}+\
myScanText{The quick brown fox jumps over the lazy dog.}
verb+myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}+\
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
add a comment |
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:
documentclass{article}
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]{expl3}
usepackage{xparse}
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
tl_set:Nn l_rn_auxOne_tl {#1}
regex_replace_all:nnN {s+} { c{space} } l_rn_auxOne_tl
textbf{tl~variable:}~tl_use:N l_rn_auxOne_tl\
seq_set_split:NnV l_rn_auxOne_seq {} l_rn_auxOne_tl
textbf{seq~variable:}~seq_use:Nn l_rn_auxOne_seq {,}\
} % myExperminent
ExplSyntaxOff
%-----------------------
begin{document}
verb+myScanText{The quick brown fox jumps over the lazy dog.}+\
myScanText{The quick brown fox jumps over the lazy dog.}
verb+myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}+\
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
Note that this replaces repeated spaces with a single space
, which I'm guessing is probably what you'd really want.
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%2f459519%2fpreserving-spaces-when-scannig-tl-variables-into-a-sequence-using-seq-set-sp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use a slower routine first splitting at spaces.
documentclass{article}
usepackage[margin=1cm]{geometry}
usepackage{xparse}
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
NewDocumentCommandmyScanText{m}
{
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
textbf{tl~variable:}~tl_use:N l_rn_auxOne_tl\
textbf{seq~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
%-----------------------
begin{document}
setlength{parindent}{0pt} % just for the example
myScanText{The quick brown fox jumps over the lazy dog.}
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
Alternative method: first replace spaces with a private token and then split with tl_map_function:NN
documentclass{article}
usepackage[margin=1cm]{geometry}
usepackage{xparse}
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
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
textbf{input:}~#1\
textbf{seq~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
%-----------------------
begin{document}
setlength{parindent}{0pt} % just for the example
myScanText{The quick brown fox jumps over the lazy dog.}
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
Whycs_new_protected:Nn __rn_space: {}
? This token should never be expanded anyway.
– Henri Menke
Nov 12 '18 at 6:17
@HenriMenke Because it should have a definition.
– egreg
Nov 12 '18 at 7:50
add a comment |
Use a slower routine first splitting at spaces.
documentclass{article}
usepackage[margin=1cm]{geometry}
usepackage{xparse}
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
NewDocumentCommandmyScanText{m}
{
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
textbf{tl~variable:}~tl_use:N l_rn_auxOne_tl\
textbf{seq~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
%-----------------------
begin{document}
setlength{parindent}{0pt} % just for the example
myScanText{The quick brown fox jumps over the lazy dog.}
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
Alternative method: first replace spaces with a private token and then split with tl_map_function:NN
documentclass{article}
usepackage[margin=1cm]{geometry}
usepackage{xparse}
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
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
textbf{input:}~#1\
textbf{seq~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
%-----------------------
begin{document}
setlength{parindent}{0pt} % just for the example
myScanText{The quick brown fox jumps over the lazy dog.}
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
Whycs_new_protected:Nn __rn_space: {}
? This token should never be expanded anyway.
– Henri Menke
Nov 12 '18 at 6:17
@HenriMenke Because it should have a definition.
– egreg
Nov 12 '18 at 7:50
add a comment |
Use a slower routine first splitting at spaces.
documentclass{article}
usepackage[margin=1cm]{geometry}
usepackage{xparse}
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
NewDocumentCommandmyScanText{m}
{
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
textbf{tl~variable:}~tl_use:N l_rn_auxOne_tl\
textbf{seq~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
%-----------------------
begin{document}
setlength{parindent}{0pt} % just for the example
myScanText{The quick brown fox jumps over the lazy dog.}
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
Alternative method: first replace spaces with a private token and then split with tl_map_function:NN
documentclass{article}
usepackage[margin=1cm]{geometry}
usepackage{xparse}
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
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
textbf{input:}~#1\
textbf{seq~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
%-----------------------
begin{document}
setlength{parindent}{0pt} % just for the example
myScanText{The quick brown fox jumps over the lazy dog.}
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
Use a slower routine first splitting at spaces.
documentclass{article}
usepackage[margin=1cm]{geometry}
usepackage{xparse}
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
NewDocumentCommandmyScanText{m}
{
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
textbf{tl~variable:}~tl_use:N l_rn_auxOne_tl\
textbf{seq~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
%-----------------------
begin{document}
setlength{parindent}{0pt} % just for the example
myScanText{The quick brown fox jumps over the lazy dog.}
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
Alternative method: first replace spaces with a private token and then split with tl_map_function:NN
documentclass{article}
usepackage[margin=1cm]{geometry}
usepackage{xparse}
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
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
textbf{input:}~#1\
textbf{seq~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
%-----------------------
begin{document}
setlength{parindent}{0pt} % just for the example
myScanText{The quick brown fox jumps over the lazy dog.}
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
edited Nov 11 '18 at 23:23
answered Nov 11 '18 at 22:25
egreg
709k8618823165
709k8618823165
Whycs_new_protected:Nn __rn_space: {}
? This token should never be expanded anyway.
– Henri Menke
Nov 12 '18 at 6:17
@HenriMenke Because it should have a definition.
– egreg
Nov 12 '18 at 7:50
add a comment |
Whycs_new_protected:Nn __rn_space: {}
? This token should never be expanded anyway.
– Henri Menke
Nov 12 '18 at 6:17
@HenriMenke Because it should have a definition.
– egreg
Nov 12 '18 at 7:50
Why
cs_new_protected:Nn __rn_space: {}
? This token should never be expanded anyway.– Henri Menke
Nov 12 '18 at 6:17
Why
cs_new_protected:Nn __rn_space: {}
? This token should never be expanded anyway.– Henri Menke
Nov 12 '18 at 6:17
@HenriMenke Because it should have a definition.
– egreg
Nov 12 '18 at 7:50
@HenriMenke Because it should have a definition.
– egreg
Nov 12 '18 at 7:50
add a comment |
You could use str_map_inline:Nn
and append to the seq
. The problem is that catcodes are all 12 then.
documentclass{article}
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]{expl3}
usepackage{xparse}
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
tl_set:Nn l_rn_auxOne_tl {#1}
textbf{tl~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 } }
textbf{seq~variable:}~seq_use:Nn l_rn_auxOne_seq {,}\
} % myExperminent
ExplSyntaxOff
%-----------------------
begin{document}
verb+myScanText{The quick brown fox jumps over the lazy dog.}+\
myScanText{The quick brown fox jumps over the lazy dog.}
verb+myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}+\
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
add a comment |
You could use str_map_inline:Nn
and append to the seq
. The problem is that catcodes are all 12 then.
documentclass{article}
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]{expl3}
usepackage{xparse}
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
tl_set:Nn l_rn_auxOne_tl {#1}
textbf{tl~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 } }
textbf{seq~variable:}~seq_use:Nn l_rn_auxOne_seq {,}\
} % myExperminent
ExplSyntaxOff
%-----------------------
begin{document}
verb+myScanText{The quick brown fox jumps over the lazy dog.}+\
myScanText{The quick brown fox jumps over the lazy dog.}
verb+myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}+\
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
add a comment |
You could use str_map_inline:Nn
and append to the seq
. The problem is that catcodes are all 12 then.
documentclass{article}
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]{expl3}
usepackage{xparse}
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
tl_set:Nn l_rn_auxOne_tl {#1}
textbf{tl~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 } }
textbf{seq~variable:}~seq_use:Nn l_rn_auxOne_seq {,}\
} % myExperminent
ExplSyntaxOff
%-----------------------
begin{document}
verb+myScanText{The quick brown fox jumps over the lazy dog.}+\
myScanText{The quick brown fox jumps over the lazy dog.}
verb+myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}+\
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
You could use str_map_inline:Nn
and append to the seq
. The problem is that catcodes are all 12 then.
documentclass{article}
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]{expl3}
usepackage{xparse}
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
tl_set:Nn l_rn_auxOne_tl {#1}
textbf{tl~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 } }
textbf{seq~variable:}~seq_use:Nn l_rn_auxOne_seq {,}\
} % myExperminent
ExplSyntaxOff
%-----------------------
begin{document}
verb+myScanText{The quick brown fox jumps over the lazy dog.}+\
myScanText{The quick brown fox jumps over the lazy dog.}
verb+myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}+\
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
answered Nov 11 '18 at 21:46
Henri Menke
69.9k8156260
69.9k8156260
add a comment |
add a comment |
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:
documentclass{article}
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]{expl3}
usepackage{xparse}
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
tl_set:Nn l_rn_auxOne_tl {#1}
regex_replace_all:nnN {s+} { c{space} } l_rn_auxOne_tl
textbf{tl~variable:}~tl_use:N l_rn_auxOne_tl\
seq_set_split:NnV l_rn_auxOne_seq {} l_rn_auxOne_tl
textbf{seq~variable:}~seq_use:Nn l_rn_auxOne_seq {,}\
} % myExperminent
ExplSyntaxOff
%-----------------------
begin{document}
verb+myScanText{The quick brown fox jumps over the lazy dog.}+\
myScanText{The quick brown fox jumps over the lazy dog.}
verb+myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}+\
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
Note that this replaces repeated spaces with a single space
, which I'm guessing is probably what you'd really want.
add a comment |
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:
documentclass{article}
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]{expl3}
usepackage{xparse}
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
tl_set:Nn l_rn_auxOne_tl {#1}
regex_replace_all:nnN {s+} { c{space} } l_rn_auxOne_tl
textbf{tl~variable:}~tl_use:N l_rn_auxOne_tl\
seq_set_split:NnV l_rn_auxOne_seq {} l_rn_auxOne_tl
textbf{seq~variable:}~seq_use:Nn l_rn_auxOne_seq {,}\
} % myExperminent
ExplSyntaxOff
%-----------------------
begin{document}
verb+myScanText{The quick brown fox jumps over the lazy dog.}+\
myScanText{The quick brown fox jumps over the lazy dog.}
verb+myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}+\
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
Note that this replaces repeated spaces with a single space
, which I'm guessing is probably what you'd really want.
add a comment |
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:
documentclass{article}
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]{expl3}
usepackage{xparse}
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
tl_set:Nn l_rn_auxOne_tl {#1}
regex_replace_all:nnN {s+} { c{space} } l_rn_auxOne_tl
textbf{tl~variable:}~tl_use:N l_rn_auxOne_tl\
seq_set_split:NnV l_rn_auxOne_seq {} l_rn_auxOne_tl
textbf{seq~variable:}~seq_use:Nn l_rn_auxOne_seq {,}\
} % myExperminent
ExplSyntaxOff
%-----------------------
begin{document}
verb+myScanText{The quick brown fox jumps over the lazy dog.}+\
myScanText{The quick brown fox jumps over the lazy dog.}
verb+myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}+\
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
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:
documentclass{article}
% RN. 11 Nov 2018
%=======================
usepackage[check-declarations,log-functions]{expl3}
usepackage{xparse}
%-----------------------
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
seq_new:N l_rn_auxOne_seq
NewDocumentCommandmyScanText{m}
{
tl_set:Nn l_rn_auxOne_tl {#1}
regex_replace_all:nnN {s+} { c{space} } l_rn_auxOne_tl
textbf{tl~variable:}~tl_use:N l_rn_auxOne_tl\
seq_set_split:NnV l_rn_auxOne_seq {} l_rn_auxOne_tl
textbf{seq~variable:}~seq_use:Nn l_rn_auxOne_seq {,}\
} % myExperminent
ExplSyntaxOff
%-----------------------
begin{document}
verb+myScanText{The quick brown fox jumps over the lazy dog.}+\
myScanText{The quick brown fox jumps over the lazy dog.}
verb+myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}+\
myScanText{The~quick~brown~fox~jumps~over~the~lazy~dog.}
end{document}
Note that this replaces repeated spaces with a single space
, which I'm guessing is probably what you'd really want.
answered Nov 11 '18 at 22:37
Andrew
30.4k34380
30.4k34380
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f459519%2fpreserving-spaces-when-scannig-tl-variables-into-a-sequence-using-seq-set-sp%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