Does expanded replace the romannumeral trick for expansion?How to do scantokens inside edef without...

Which sphere is fastest?

How should I tell my manager I'm not paying for an optional after work event I'm not going to?

Endgame puzzle: How to avoid stalemate and win?

Why did WWI include Japan?

Why symmetry transformations have to commute with Hamiltonian?

Constitutional limitation of criminalizing behavior in US law?

Should I mention being denied entry to UK due to a confusion in my Visa and Ticket bookings?

To kill a cuckoo

Which US defense organization would respond to an invasion like this?

Dihedral group D4 composition with custom labels

SOQL query WHERE filter by specific months

Is there an age requirement to play in Adventurers League?

Is 'contemporary' ambiguous and if so is there a better word?

Would a small hole in a Faraday cage drastically reduce its effectiveness at blocking interference?

My first c++ game (snake console game)

Is an HNN extension of a virtually torsion-free group virtually torsion-free?

Should homeowners insurance cover the cost of the home?

Does "Captain Marvel" contain spoilers for "Avengers: Infinity War"?

Notation: What does the tilde below of the expectation mean?

Mug and wireframe entirely disappeared

How does the reduce() method work in Java 8?

What is the closest airport to the center of the city it serves?

Where to draw the line between quantum mechanics theory and its interpretation(s)?

How do LIGO and VIRGO know that a gravitational wave has its origin in a neutron star or a black hole?



Does expanded replace the romannumeral trick for expansion?


How to do scantokens inside edef without triggering “Runaway definition”Does noexpand have to be a primitive?How do I examine a token?How to vanish relax inserted by TeX itselfWhy isn't everything expandable?Expansion in numexpr…relax versus pdfstrcmpA typeout (or expandable command) that can expand once - or with variable levels of expansion?How does your mind bend expandafter to its will?The laws of expansion (chardeffoo=<number>foo)Distinguish active characters from non-active pendants with expansion-methods only?













3















TeXLive 2019 is here :D



One of its awaited features is the new expanded primitive now available in all of the main engines (only available in LuaTeX in previous years) thanks to Joseph Wright.



What we had up to now was:




  • Full expansion with edef and the like;

    Pros: expands the entire token list respecting protected (any form thereof) tokens

    Cons: being an assignment operation, it is not itself expandable;


  • Partial expansion exploiting romannumeral, which expands tokens while looking for an ⟨integer⟩ and a trailing ⟨optional space⟩;

    Pros: is expandable, allowing one1 to write some really interesting macros (including an expandable emulation of the expanded primitive);

    Cons: only expands the “head” of the token list, stopping as soon as it finds an expandable token which does not fit into its argument specification;



expanded gives a nice mix of both, allowing us to get the full expansion of a token list while being itself expandable, apparently covering a great deal of the use-cases of both edef and romannumeral.



Of course edef still is really useful when the expansion of the tokens needs to be stored in a macro, and the produced macro can take arguments normally, which aren't features of expanded.



The romannumeral trick, however, seems to have lost much of it's usefulness with expanded. From what I understand, many situations which required romannumeral to get the full expansion of something, now can use expanded for the same effect with a proper expansion primitive.



I know that the answer to the question in the title is “no” because there are a few situations in which romannumeral is still useful. The main one, I think, are undelimited arguments; expanded requires the material to be expanded as a ⟨general text⟩ argument, while romannumeral can be put in the token and act indefinitely, until an unexpandable token is found. Another situation is, of course, when one really wants only the head of the token list expanded, then romannumeral is the tool for the job.



But both these situations seem much smaller than the entire scope of using romannumeral for expansion. Thus my question (finally) is: can the expansion trick with romannumeral be replaced mostly everywhere (as an example I can mention the LaTeX3 kernel, which heavily uses this romannumeral-powered expansion)? What other situations require romannumeral for expansion and will not work with expanded?





1In this case a very particular one :)










share|improve this question



























    3















    TeXLive 2019 is here :D



    One of its awaited features is the new expanded primitive now available in all of the main engines (only available in LuaTeX in previous years) thanks to Joseph Wright.



    What we had up to now was:




    • Full expansion with edef and the like;

      Pros: expands the entire token list respecting protected (any form thereof) tokens

      Cons: being an assignment operation, it is not itself expandable;


    • Partial expansion exploiting romannumeral, which expands tokens while looking for an ⟨integer⟩ and a trailing ⟨optional space⟩;

      Pros: is expandable, allowing one1 to write some really interesting macros (including an expandable emulation of the expanded primitive);

      Cons: only expands the “head” of the token list, stopping as soon as it finds an expandable token which does not fit into its argument specification;



    expanded gives a nice mix of both, allowing us to get the full expansion of a token list while being itself expandable, apparently covering a great deal of the use-cases of both edef and romannumeral.



    Of course edef still is really useful when the expansion of the tokens needs to be stored in a macro, and the produced macro can take arguments normally, which aren't features of expanded.



    The romannumeral trick, however, seems to have lost much of it's usefulness with expanded. From what I understand, many situations which required romannumeral to get the full expansion of something, now can use expanded for the same effect with a proper expansion primitive.



    I know that the answer to the question in the title is “no” because there are a few situations in which romannumeral is still useful. The main one, I think, are undelimited arguments; expanded requires the material to be expanded as a ⟨general text⟩ argument, while romannumeral can be put in the token and act indefinitely, until an unexpandable token is found. Another situation is, of course, when one really wants only the head of the token list expanded, then romannumeral is the tool for the job.



    But both these situations seem much smaller than the entire scope of using romannumeral for expansion. Thus my question (finally) is: can the expansion trick with romannumeral be replaced mostly everywhere (as an example I can mention the LaTeX3 kernel, which heavily uses this romannumeral-powered expansion)? What other situations require romannumeral for expansion and will not work with expanded?





    1In this case a very particular one :)










    share|improve this question

























      3












      3








      3








      TeXLive 2019 is here :D



      One of its awaited features is the new expanded primitive now available in all of the main engines (only available in LuaTeX in previous years) thanks to Joseph Wright.



      What we had up to now was:




      • Full expansion with edef and the like;

        Pros: expands the entire token list respecting protected (any form thereof) tokens

        Cons: being an assignment operation, it is not itself expandable;


      • Partial expansion exploiting romannumeral, which expands tokens while looking for an ⟨integer⟩ and a trailing ⟨optional space⟩;

        Pros: is expandable, allowing one1 to write some really interesting macros (including an expandable emulation of the expanded primitive);

        Cons: only expands the “head” of the token list, stopping as soon as it finds an expandable token which does not fit into its argument specification;



      expanded gives a nice mix of both, allowing us to get the full expansion of a token list while being itself expandable, apparently covering a great deal of the use-cases of both edef and romannumeral.



      Of course edef still is really useful when the expansion of the tokens needs to be stored in a macro, and the produced macro can take arguments normally, which aren't features of expanded.



      The romannumeral trick, however, seems to have lost much of it's usefulness with expanded. From what I understand, many situations which required romannumeral to get the full expansion of something, now can use expanded for the same effect with a proper expansion primitive.



      I know that the answer to the question in the title is “no” because there are a few situations in which romannumeral is still useful. The main one, I think, are undelimited arguments; expanded requires the material to be expanded as a ⟨general text⟩ argument, while romannumeral can be put in the token and act indefinitely, until an unexpandable token is found. Another situation is, of course, when one really wants only the head of the token list expanded, then romannumeral is the tool for the job.



      But both these situations seem much smaller than the entire scope of using romannumeral for expansion. Thus my question (finally) is: can the expansion trick with romannumeral be replaced mostly everywhere (as an example I can mention the LaTeX3 kernel, which heavily uses this romannumeral-powered expansion)? What other situations require romannumeral for expansion and will not work with expanded?





      1In this case a very particular one :)










      share|improve this question














      TeXLive 2019 is here :D



      One of its awaited features is the new expanded primitive now available in all of the main engines (only available in LuaTeX in previous years) thanks to Joseph Wright.



      What we had up to now was:




      • Full expansion with edef and the like;

        Pros: expands the entire token list respecting protected (any form thereof) tokens

        Cons: being an assignment operation, it is not itself expandable;


      • Partial expansion exploiting romannumeral, which expands tokens while looking for an ⟨integer⟩ and a trailing ⟨optional space⟩;

        Pros: is expandable, allowing one1 to write some really interesting macros (including an expandable emulation of the expanded primitive);

        Cons: only expands the “head” of the token list, stopping as soon as it finds an expandable token which does not fit into its argument specification;



      expanded gives a nice mix of both, allowing us to get the full expansion of a token list while being itself expandable, apparently covering a great deal of the use-cases of both edef and romannumeral.



      Of course edef still is really useful when the expansion of the tokens needs to be stored in a macro, and the produced macro can take arguments normally, which aren't features of expanded.



      The romannumeral trick, however, seems to have lost much of it's usefulness with expanded. From what I understand, many situations which required romannumeral to get the full expansion of something, now can use expanded for the same effect with a proper expansion primitive.



      I know that the answer to the question in the title is “no” because there are a few situations in which romannumeral is still useful. The main one, I think, are undelimited arguments; expanded requires the material to be expanded as a ⟨general text⟩ argument, while romannumeral can be put in the token and act indefinitely, until an unexpandable token is found. Another situation is, of course, when one really wants only the head of the token list expanded, then romannumeral is the tool for the job.



      But both these situations seem much smaller than the entire scope of using romannumeral for expansion. Thus my question (finally) is: can the expansion trick with romannumeral be replaced mostly everywhere (as an example I can mention the LaTeX3 kernel, which heavily uses this romannumeral-powered expansion)? What other situations require romannumeral for expansion and will not work with expanded?





      1In this case a very particular one :)







      tex-core expansion programming texlive-2019






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 5 hours ago









      Phelype OleinikPhelype Oleinik

      26.7k54792




      26.7k54792






















          1 Answer
          1






          active

          oldest

          votes


















          3














          In many case the romannumeral trick is obsolete, but there are at least two cases where it still is useful.



          The first is in that as mentioned in the question it's 'open ended', whereas expanded requires an argument to be grabbed. The second is that romannumeral expansion works through tokens exactly as TeX itself does when typesetting, up to the point it finds some 'payload'. This allows us to deal with any expandable material and then 'look ahead' at the first non-expandable token. An example from l3galley:



          cs_new_protected:Npn galley_par:
          {
          s__galley_par_omit
          exp_after:wN __galley_par_auxi: exp:w exp_end_continue_f:w
          }
          cs_new_protected:Npn __galley_par_auxi:
          {
          peek_meaning:NTF s__galley_par_omit
          { __galley_par_aux:N }
          { __galley_par_auxii: }
          }
          cs_new_protected:Npn __galley_par_aux:N #1
          {
          str_if_eq:nnF {#1} { s__galley_par_omit }
          {
          __galley_par_auxii:
          #1
          }
          }


          The romannumeral here is hidden inside exp:w, but the idea is simple. The expansion will continue until some non-expandable token is found. We then 'come back' to a look-ahead, which checks for a token that is exactly equivalent to s__galley_par_omit, a marker for consecutive par tokens. This needs the open-ended nature of romannumeral and the fact that it stops.



          It's also worth noting that romannumeral ignores protected status: that shows up above, and would also be handy in implementing for example halign in macros. (This is another place we need a look-ahead.)





          These aspects are quite specialised, and in most cases do not apply. The bigger barrier to shifting to expanded is that it is only now generally available: it will be many years before it is safe to assume that expanded is safe to use without a fall-back.






          share|improve this answer


























          • Oh, I completely overlooked the protected macros. I think this would make a nice way to test if a macro is protected. The look ahead thing looks interesting though :)

            – Phelype Oleinik
            4 hours ago











          • @Myself No, it wouldn't and expl3 already has token_if_protected_macro:NTF :)

            – Phelype Oleinik
            3 hours ago












          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%2f489063%2fdoes-expanded-replace-the-romannumeral-trick-for-expansion%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          In many case the romannumeral trick is obsolete, but there are at least two cases where it still is useful.



          The first is in that as mentioned in the question it's 'open ended', whereas expanded requires an argument to be grabbed. The second is that romannumeral expansion works through tokens exactly as TeX itself does when typesetting, up to the point it finds some 'payload'. This allows us to deal with any expandable material and then 'look ahead' at the first non-expandable token. An example from l3galley:



          cs_new_protected:Npn galley_par:
          {
          s__galley_par_omit
          exp_after:wN __galley_par_auxi: exp:w exp_end_continue_f:w
          }
          cs_new_protected:Npn __galley_par_auxi:
          {
          peek_meaning:NTF s__galley_par_omit
          { __galley_par_aux:N }
          { __galley_par_auxii: }
          }
          cs_new_protected:Npn __galley_par_aux:N #1
          {
          str_if_eq:nnF {#1} { s__galley_par_omit }
          {
          __galley_par_auxii:
          #1
          }
          }


          The romannumeral here is hidden inside exp:w, but the idea is simple. The expansion will continue until some non-expandable token is found. We then 'come back' to a look-ahead, which checks for a token that is exactly equivalent to s__galley_par_omit, a marker for consecutive par tokens. This needs the open-ended nature of romannumeral and the fact that it stops.



          It's also worth noting that romannumeral ignores protected status: that shows up above, and would also be handy in implementing for example halign in macros. (This is another place we need a look-ahead.)





          These aspects are quite specialised, and in most cases do not apply. The bigger barrier to shifting to expanded is that it is only now generally available: it will be many years before it is safe to assume that expanded is safe to use without a fall-back.






          share|improve this answer


























          • Oh, I completely overlooked the protected macros. I think this would make a nice way to test if a macro is protected. The look ahead thing looks interesting though :)

            – Phelype Oleinik
            4 hours ago











          • @Myself No, it wouldn't and expl3 already has token_if_protected_macro:NTF :)

            – Phelype Oleinik
            3 hours ago
















          3














          In many case the romannumeral trick is obsolete, but there are at least two cases where it still is useful.



          The first is in that as mentioned in the question it's 'open ended', whereas expanded requires an argument to be grabbed. The second is that romannumeral expansion works through tokens exactly as TeX itself does when typesetting, up to the point it finds some 'payload'. This allows us to deal with any expandable material and then 'look ahead' at the first non-expandable token. An example from l3galley:



          cs_new_protected:Npn galley_par:
          {
          s__galley_par_omit
          exp_after:wN __galley_par_auxi: exp:w exp_end_continue_f:w
          }
          cs_new_protected:Npn __galley_par_auxi:
          {
          peek_meaning:NTF s__galley_par_omit
          { __galley_par_aux:N }
          { __galley_par_auxii: }
          }
          cs_new_protected:Npn __galley_par_aux:N #1
          {
          str_if_eq:nnF {#1} { s__galley_par_omit }
          {
          __galley_par_auxii:
          #1
          }
          }


          The romannumeral here is hidden inside exp:w, but the idea is simple. The expansion will continue until some non-expandable token is found. We then 'come back' to a look-ahead, which checks for a token that is exactly equivalent to s__galley_par_omit, a marker for consecutive par tokens. This needs the open-ended nature of romannumeral and the fact that it stops.



          It's also worth noting that romannumeral ignores protected status: that shows up above, and would also be handy in implementing for example halign in macros. (This is another place we need a look-ahead.)





          These aspects are quite specialised, and in most cases do not apply. The bigger barrier to shifting to expanded is that it is only now generally available: it will be many years before it is safe to assume that expanded is safe to use without a fall-back.






          share|improve this answer


























          • Oh, I completely overlooked the protected macros. I think this would make a nice way to test if a macro is protected. The look ahead thing looks interesting though :)

            – Phelype Oleinik
            4 hours ago











          • @Myself No, it wouldn't and expl3 already has token_if_protected_macro:NTF :)

            – Phelype Oleinik
            3 hours ago














          3












          3








          3







          In many case the romannumeral trick is obsolete, but there are at least two cases where it still is useful.



          The first is in that as mentioned in the question it's 'open ended', whereas expanded requires an argument to be grabbed. The second is that romannumeral expansion works through tokens exactly as TeX itself does when typesetting, up to the point it finds some 'payload'. This allows us to deal with any expandable material and then 'look ahead' at the first non-expandable token. An example from l3galley:



          cs_new_protected:Npn galley_par:
          {
          s__galley_par_omit
          exp_after:wN __galley_par_auxi: exp:w exp_end_continue_f:w
          }
          cs_new_protected:Npn __galley_par_auxi:
          {
          peek_meaning:NTF s__galley_par_omit
          { __galley_par_aux:N }
          { __galley_par_auxii: }
          }
          cs_new_protected:Npn __galley_par_aux:N #1
          {
          str_if_eq:nnF {#1} { s__galley_par_omit }
          {
          __galley_par_auxii:
          #1
          }
          }


          The romannumeral here is hidden inside exp:w, but the idea is simple. The expansion will continue until some non-expandable token is found. We then 'come back' to a look-ahead, which checks for a token that is exactly equivalent to s__galley_par_omit, a marker for consecutive par tokens. This needs the open-ended nature of romannumeral and the fact that it stops.



          It's also worth noting that romannumeral ignores protected status: that shows up above, and would also be handy in implementing for example halign in macros. (This is another place we need a look-ahead.)





          These aspects are quite specialised, and in most cases do not apply. The bigger barrier to shifting to expanded is that it is only now generally available: it will be many years before it is safe to assume that expanded is safe to use without a fall-back.






          share|improve this answer















          In many case the romannumeral trick is obsolete, but there are at least two cases where it still is useful.



          The first is in that as mentioned in the question it's 'open ended', whereas expanded requires an argument to be grabbed. The second is that romannumeral expansion works through tokens exactly as TeX itself does when typesetting, up to the point it finds some 'payload'. This allows us to deal with any expandable material and then 'look ahead' at the first non-expandable token. An example from l3galley:



          cs_new_protected:Npn galley_par:
          {
          s__galley_par_omit
          exp_after:wN __galley_par_auxi: exp:w exp_end_continue_f:w
          }
          cs_new_protected:Npn __galley_par_auxi:
          {
          peek_meaning:NTF s__galley_par_omit
          { __galley_par_aux:N }
          { __galley_par_auxii: }
          }
          cs_new_protected:Npn __galley_par_aux:N #1
          {
          str_if_eq:nnF {#1} { s__galley_par_omit }
          {
          __galley_par_auxii:
          #1
          }
          }


          The romannumeral here is hidden inside exp:w, but the idea is simple. The expansion will continue until some non-expandable token is found. We then 'come back' to a look-ahead, which checks for a token that is exactly equivalent to s__galley_par_omit, a marker for consecutive par tokens. This needs the open-ended nature of romannumeral and the fact that it stops.



          It's also worth noting that romannumeral ignores protected status: that shows up above, and would also be handy in implementing for example halign in macros. (This is another place we need a look-ahead.)





          These aspects are quite specialised, and in most cases do not apply. The bigger barrier to shifting to expanded is that it is only now generally available: it will be many years before it is safe to assume that expanded is safe to use without a fall-back.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 4 hours ago









          Henri Menke

          78.6k9172285




          78.6k9172285










          answered 4 hours ago









          Joseph WrightJoseph Wright

          206k23567897




          206k23567897













          • Oh, I completely overlooked the protected macros. I think this would make a nice way to test if a macro is protected. The look ahead thing looks interesting though :)

            – Phelype Oleinik
            4 hours ago











          • @Myself No, it wouldn't and expl3 already has token_if_protected_macro:NTF :)

            – Phelype Oleinik
            3 hours ago



















          • Oh, I completely overlooked the protected macros. I think this would make a nice way to test if a macro is protected. The look ahead thing looks interesting though :)

            – Phelype Oleinik
            4 hours ago











          • @Myself No, it wouldn't and expl3 already has token_if_protected_macro:NTF :)

            – Phelype Oleinik
            3 hours ago

















          Oh, I completely overlooked the protected macros. I think this would make a nice way to test if a macro is protected. The look ahead thing looks interesting though :)

          – Phelype Oleinik
          4 hours ago





          Oh, I completely overlooked the protected macros. I think this would make a nice way to test if a macro is protected. The look ahead thing looks interesting though :)

          – Phelype Oleinik
          4 hours ago













          @Myself No, it wouldn't and expl3 already has token_if_protected_macro:NTF :)

          – Phelype Oleinik
          3 hours ago





          @Myself No, it wouldn't and expl3 already has token_if_protected_macro:NTF :)

          – Phelype Oleinik
          3 hours ago


















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f489063%2fdoes-expanded-replace-the-romannumeral-trick-for-expansion%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







          Popular posts from this blog

          Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

          Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

          Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...