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









up vote
4
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









share|improve this question

























    up vote
    4
    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









    share|improve this question























      up vote
      4
      down vote

      favorite









      up vote
      4
      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









      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?



      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






      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,53411322




      1,53411322




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          4
          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


          enter image description here



          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





          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

















          up vote
          4
          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


          enter image description here






          share|improve this answer



























            up vote
            2
            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:



            enter image description here



            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.






            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',
              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








              up vote
              4
              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


              enter image description here



              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





              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














              up vote
              4
              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


              enter image description here



              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





              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












              up vote
              4
              down vote



              accepted







              up vote
              4
              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


              enter image description here



              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





              share|improve this answer














              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


              enter image description here



              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






              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

              705k8618763155




              705k8618763155











              • 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










              up vote
              4
              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


              enter image description here






              share|improve this answer
























                up vote
                4
                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


                enter image description here






                share|improve this answer






















                  up vote
                  4
                  down vote










                  up vote
                  4
                  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


                  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.



                  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


                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 11 at 21:46









                  Henri Menke

                  69k7153257




                  69k7153257




















                      up vote
                      2
                      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:



                      enter image description here



                      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.






                      share|improve this answer
























                        up vote
                        2
                        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:



                        enter image description here



                        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.






                        share|improve this answer






















                          up vote
                          2
                          down vote










                          up vote
                          2
                          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:



                          enter image description here



                          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.






                          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:



                          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.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 11 at 22:37









                          Andrew

                          30.3k34380




                          30.3k34380



























                              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







                              這個網誌中的熱門文章

                              How to read a connectionString WITH PROVIDER in .NET Core?

                              In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                              Museum of Modern and Contemporary Art of Trento and Rovereto