Preserving spaces when scannig `tl` variables into a sequence using `seq_set_split`












4














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}









share|improve this question



























    4














    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}









    share|improve this question

























      4












      4








      4







      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}









      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 21:31









      Reinhard Neuwirth

      1,55111322




      1,55111322






















          3 Answers
          3






          active

          oldest

          votes


















          4














          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}


          enter image description here



          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}





          share|improve this answer























          • Why cs_new_protected:Nn __rn_space: {}? This token should never be expanded anyway.
            – Henri Menke
            Nov 12 at 6:17










          • @HenriMenke Because it should have a definition.
            – egreg
            Nov 12 at 7:50



















          4














          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}


          enter image description here






          share|improve this answer





























            2














            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:



            enter image description here



            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.






            share|improve this answer





















              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
              });


              }
              });














              draft saved

              draft discarded


















              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









              4














              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}


              enter image description here



              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}





              share|improve this answer























              • Why cs_new_protected:Nn __rn_space: {}? This token should never be expanded anyway.
                – Henri Menke
                Nov 12 at 6:17










              • @HenriMenke Because it should have a definition.
                – egreg
                Nov 12 at 7:50
















              4














              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}


              enter image description here



              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}





              share|improve this answer























              • Why cs_new_protected:Nn __rn_space: {}? This token should never be expanded anyway.
                – Henri Menke
                Nov 12 at 6:17










              • @HenriMenke Because it should have a definition.
                – egreg
                Nov 12 at 7:50














              4












              4








              4






              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}


              enter image description here



              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}





              share|improve this answer














              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}


              enter image description here



              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}






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 11 at 23:23

























              answered Nov 11 at 22:25









              egreg

              708k8618823163




              708k8618823163












              • Why cs_new_protected:Nn __rn_space: {}? This token should never be expanded anyway.
                – Henri Menke
                Nov 12 at 6:17










              • @HenriMenke Because it should have a definition.
                – egreg
                Nov 12 at 7:50


















              • Why cs_new_protected:Nn __rn_space: {}? This token should never be expanded anyway.
                – Henri Menke
                Nov 12 at 6:17










              • @HenriMenke Because it should have a definition.
                – egreg
                Nov 12 at 7:50
















              Why cs_new_protected:Nn __rn_space: {}? This token should never be expanded anyway.
              – Henri Menke
              Nov 12 at 6:17




              Why cs_new_protected:Nn __rn_space: {}? This token should never be expanded anyway.
              – Henri Menke
              Nov 12 at 6:17












              @HenriMenke Because it should have a definition.
              – egreg
              Nov 12 at 7:50




              @HenriMenke Because it should have a definition.
              – egreg
              Nov 12 at 7:50











              4














              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}


              enter image description here






              share|improve this answer


























                4














                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}


                enter image description here






                share|improve this answer
























                  4












                  4








                  4






                  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}


                  enter image description here






                  share|improve this answer












                  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}


                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 11 at 21:46









                  Henri Menke

                  69.8k8155260




                  69.8k8155260























                      2














                      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:



                      enter image description here



                      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.






                      share|improve this answer


























                        2














                        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:



                        enter image description here



                        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.






                        share|improve this answer
























                          2












                          2








                          2






                          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:



                          enter image description here



                          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.






                          share|improve this answer












                          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:



                          enter image description here



                          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.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 11 at 22:37









                          Andrew

                          30.4k34380




                          30.4k34380






























                              draft saved

                              draft discarded




















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              這個網誌中的熱門文章

                              Tangent Lines Diagram Along Smooth Curve

                              Yusuf al-Mu'taman ibn Hud

                              Zucchini