How to make a pipe-divided tuple?Emulate a “tuple” data structure when the syntax for creating a tuple is predefined and cannot be alteredHow to use a Pipe (|) with indices like an IntegralHow to make pipe to grow with both sides?Underbraces in Matrix Divided in BlocksDesigning a new tuple of Algebra OperatorsDefine macro for sequence/list/tuple macrosDivided differences tableEmbedding a simple tikz diagram within a tuple equation

I won a car in a poker game. How is that taxed in Canada?

How should Thaumaturgy's "three times as loud as normal" be interpreted?

Round away from zero

Why does the UK Prime Minister need the permission of Parliament to call a general election?

These roommates throw strange parties

Why is Sojdlg123aljg a common password?

What is the purpose of the rotating plate in front of the lock?

French equivalent of "my cup of tea"

Temporarily simulate being offline programmatically

Why are UK MPs allowed to not vote (but it counts as a no)?

In apex, how to replace the value in the string

Golfball Dimples on spaceships (and planes)?

Old sci fi book, addictive soft drinks

"syntax error near unexpected token" after editing .bashrc

Do 643,000 Americans go bankrupt every year due to medical bills?

How to calculate the power level of a Commander deck?

Looking for the comic book where Spider-Man was [mistakenly] addressed as Super-Man

Need help figure out a Fibonacci related math trick

Entering the US with dual citizenship but US passport is long expired?

Did the Byzantines ever attempt to move their capital to Rome?

Connect the wires without setting off the bomb

Phrase request for "work in" in the context of gyms

Was Rosie the Riveter sourced from a Michelangelo painting?

Sinning and G-d's will, what's wrong with this logic?



How to make a pipe-divided tuple?


Emulate a “tuple” data structure when the syntax for creating a tuple is predefined and cannot be alteredHow to use a Pipe (|) with indices like an IntegralHow to make pipe to grow with both sides?Underbraces in Matrix Divided in BlocksDesigning a new tuple of Algebra OperatorsDefine macro for sequence/list/tuple macrosDivided differences tableEmbedding a simple tikz diagram within a tuple equation






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I'm trying to write a macro, tup that will effectively expand this:



tup b 


to this:



leftlangle a ~middle|~ b ~middle|~ ... ~middle|~ z rightrangle


I tried the following, but it only puts down the first separator and then stops.



documentclass[preview]standalone

newcommandbrak[1]ensuremathleftlangle#1rightrangle

makeatletter
newcommandtup[1]%
begingroup%
@tempswafalse%
def@sep~middle%
edef@tempa#1%
expandafterbrakexpandafterexpandafter@tuploop@temparelax%
endgroup%

def@tuploop#1|#2relax%
if@tempswa@sepelse@tempswatruefi#1
begingroup
ifxrelax#2relax
renewcommandnextendgroup%
else
renewcommandnextendgroup@tuploop#2relax%
fi
next

makeatother

begindocument
$tupb$
enddocument


bad output -- only one pipe character



However, if I change the definition of @sep to def@sep~ then it "works" and puts the pipe characters in between



ok output -- both pipe characters, but no height adjustment



I believe middle might be expanding too early, but I'm not sure what to do. How can I get this to work?










share|improve this question









New contributor



Alex Reinking is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



























    3















    I'm trying to write a macro, tup that will effectively expand this:



    tup b 


    to this:



    leftlangle a ~middle|~ b ~middle|~ ... ~middle|~ z rightrangle


    I tried the following, but it only puts down the first separator and then stops.



    documentclass[preview]standalone

    newcommandbrak[1]ensuremathleftlangle#1rightrangle

    makeatletter
    newcommandtup[1]%
    begingroup%
    @tempswafalse%
    def@sep~middle%
    edef@tempa#1%
    expandafterbrakexpandafterexpandafter@tuploop@temparelax%
    endgroup%

    def@tuploop#1|#2relax%
    if@tempswa@sepelse@tempswatruefi#1
    begingroup
    ifxrelax#2relax
    renewcommandnextendgroup%
    else
    renewcommandnextendgroup@tuploop#2relax%
    fi
    next

    makeatother

    begindocument
    $tupb$
    enddocument


    bad output -- only one pipe character



    However, if I change the definition of @sep to def@sep~ then it "works" and puts the pipe characters in between



    ok output -- both pipe characters, but no height adjustment



    I believe middle might be expanding too early, but I'm not sure what to do. How can I get this to work?










    share|improve this question









    New contributor



    Alex Reinking is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      3












      3








      3








      I'm trying to write a macro, tup that will effectively expand this:



      tup b 


      to this:



      leftlangle a ~middle|~ b ~middle|~ ... ~middle|~ z rightrangle


      I tried the following, but it only puts down the first separator and then stops.



      documentclass[preview]standalone

      newcommandbrak[1]ensuremathleftlangle#1rightrangle

      makeatletter
      newcommandtup[1]%
      begingroup%
      @tempswafalse%
      def@sep~middle%
      edef@tempa#1%
      expandafterbrakexpandafterexpandafter@tuploop@temparelax%
      endgroup%

      def@tuploop#1|#2relax%
      if@tempswa@sepelse@tempswatruefi#1
      begingroup
      ifxrelax#2relax
      renewcommandnextendgroup%
      else
      renewcommandnextendgroup@tuploop#2relax%
      fi
      next

      makeatother

      begindocument
      $tupb$
      enddocument


      bad output -- only one pipe character



      However, if I change the definition of @sep to def@sep~ then it "works" and puts the pipe characters in between



      ok output -- both pipe characters, but no height adjustment



      I believe middle might be expanding too early, but I'm not sure what to do. How can I get this to work?










      share|improve this question









      New contributor



      Alex Reinking is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I'm trying to write a macro, tup that will effectively expand this:



      tup b 


      to this:



      leftlangle a ~middle|~ b ~middle|~ ... ~middle|~ z rightrangle


      I tried the following, but it only puts down the first separator and then stops.



      documentclass[preview]standalone

      newcommandbrak[1]ensuremathleftlangle#1rightrangle

      makeatletter
      newcommandtup[1]%
      begingroup%
      @tempswafalse%
      def@sep~middle%
      edef@tempa#1%
      expandafterbrakexpandafterexpandafter@tuploop@temparelax%
      endgroup%

      def@tuploop#1|#2relax%
      if@tempswa@sepelse@tempswatruefi#1
      begingroup
      ifxrelax#2relax
      renewcommandnextendgroup%
      else
      renewcommandnextendgroup@tuploop#2relax%
      fi
      next

      makeatother

      begindocument
      $tupb$
      enddocument


      bad output -- only one pipe character



      However, if I change the definition of @sep to def@sep~ then it "works" and puts the pipe characters in between



      ok output -- both pipe characters, but no height adjustment



      I believe middle might be expanding too early, but I'm not sure what to do. How can I get this to work?







      math-mode macros






      share|improve this question









      New contributor



      Alex Reinking is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question









      New contributor



      Alex Reinking is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question








      edited 8 hours ago







      Alex Reinking













      New contributor



      Alex Reinking is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked 8 hours ago









      Alex ReinkingAlex Reinking

      1185 bronze badges




      1185 bronze badges




      New contributor



      Alex Reinking is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      Alex Reinking is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.

























          4 Answers
          4






          active

          oldest

          votes


















          4
















          I don't think you need a loop:



          enter image description here



          documentclassarticle

          begingroup
          lccode`~=`|
          lowercaseendgroup
          deftup#1="8000leftlangle#1rightrangle

          begindocument

          [
          tup b + tupa
          ]

          enddocument





          share|improve this answer

























          • Do you mind explaining how this works a little bit? It seems very cool, but I don't know how I would have ever come up with it.

            – Alex Reinking
            6 hours ago











          • @AlexReinking it just gives | an active definition that expands to ;middlevert; so you don't need any looping. The definition uses mathcode "8000 (math active) so it is only locally special within that argument and other uses of | not inside the argument are not affected.

            – David Carlisle
            6 hours ago


















          5
















          As a general rule, I recommend to avoid left and right whenever possible.



          Here's an implementation with a syntax similar to commands defined with DeclarePairedDelimiter from mathtools.



          The unadorned command uses normal size; in the optional argument big, Big, bigg or Bigg can appear. The * means using automatic sizing.



          Spaces in the mandatory argument are ignored, so tupb is the same as tup c.



          documentclassarticle
          usepackageamsmath
          usepackagexparse

          ExplSyntaxOn

          NewDocumentCommandtupsom

          IfBooleanTF#1

          tl_set:Nn l__reinking_tup_open_tl leftlangle
          tl_set:Nn l__reinking_tup_middle_tl ;
          tl_set:Nn l__reinking_tup_close_tl rightrangle


          IfNoValueTF#2

          tl_set:Nn l__reinking_tup_open_tl langle
          tl_set:Nn l__reinking_tup_middle_tl mathrel
          tl_set:Nn l__reinking_tup_close_tl rangle


          tl_set:Nn l__reinking_tup_open_tl mathopen#2langle
          tl_set:Nn l__reinking_tup_middle_tl mathrel#2
          tl_set:Nn l__reinking_tup_close_tl mathclose#2rangle


          __reinking_tup:n #3


          tl_new:N l__reinking_tup_open_tl
          tl_new:N l__reinking_tup_middle_tl
          tl_new:N l__reinking_tup_close_tl
          seq_new:N l__reinking_tup_items_seq

          cs_new_protected:Nn __reinking_tup:n

          seq_set_split:Nnn l__reinking_tup_items_seq #1
          l__reinking_tup_open_tl
          seq_use:NV l__reinking_tup_items_seq l__reinking_tup_middle_tl
          l__reinking_tup_close_tl

          cs_generate_variant:Nn seq_use:Nn NV

          ExplSyntaxOff

          begindocument

          $tupa$
          quad
          $tup[big]a$
          quad
          $tup[Big]a$
          quad
          $tup*dots$

          enddocument


          enter image description here



          A package-free version, which indiscriminately uses left, middle and right. The items are absorbed one at a time and appended to a list, then the list is executed.



          documentclassarticle
          usepackageamsmath

          makeatletter
          newcommandtup[1]%
          def@tup@list%
          @tup#1
          def@tup#1|%
          ifx@tup#1relax
          expandafter@firstoftwo
          else
          expandafter@secondoftwo
          fi
          leftlangle@tup@listrightrangle%
          ifx@tup@list@empty@tup@append#1else@tup@append;#1fi@tup%

          def@tup@append#1%
          expandafterdefexpandafter@tup@listexpandafter@tup@list#1%

          makeatother

          begindocument

          $tupa$

          $tupa$

          enddocument


          This way there's no problem with groups implicitly formed by left, middle and right.






          share|improve this answer



























          • Unfortunately, the publishing system I'm submitting to does not have xparse whitelisted.

            – Alex Reinking
            7 hours ago











          • @AlexReinking Too bad. Do you really need left, middle and right?

            – egreg
            7 hours ago












          • @AlexReinking I added a package-free version.

            – egreg
            7 hours ago











          • Perhaps ifx@tup#1 in case one uses tupaa

            – Phelype Oleinik
            6 hours ago






          • 1





            @PhelypeOleinik You're right. I opted for ifx@tup#1relax which also copes with an empty argument.

            – egreg
            6 hours ago



















          3
















          Your command was almost working. If you put more items in tup, like $tupc$ you'd see this:




          enter image description here




          it's not the first item which is left out, rather they are grouped in pairs. Your command starts with a leftlangle, which starts a "math left group" and with the @tempswa switch set to false. In the first iteration of @tuploop you do if@tempswa@sepelse@tempswatruefi which expands to @tempswatrue, meaning that no @sep is inserted now, and @tempswa is now true. The command then inserts the first item (a) and proceeds to the next iteration.



          On the second iteration, @tempswa is true and if@tempswa@sepelse@tempswatruefi expands to @sep, which inserts a middle| (the separator after a). The middle primitive will end the "math left group" started by leftlangle and will start another "math left group". However, when the first group ended, your @tempswa switch was restored to its value outside the current group, which is false! And now the command inserts b and goes to the third iteration, but now with @tempswa set to false once again.



          So your command was actually inserting <token>|<token> and then <token>|<token>, and so on, due to the end of group triggered by middle. You could circumvent this with some aftergroup magic, or simply making a gloabl assignment to the switch:



          if@tempswa@sepelseglobal@tempswatruefi


          However, as egreg said in the comment, @tempswa is supposed to be set locally only, so it would be better if you created a newififg@insertsep and then always used globalg@insertseptrue and globalg@insertsepfalse.



          And since meanwhile egreg posted a much more elaborate expl3 answer than the one-liner I would post, I'll stop here ;-)






          share|improve this answer



























          • if@tempswa should only be set locally. A different conditional to be always used globally would be preferable.

            – egreg
            7 hours ago











          • @egreg How would I know that without g_...? ;-) Thanks for pointing it out, I added a note in the answer.

            – Phelype Oleinik
            6 hours ago


















          2
















          There seems to be space for one more answer, in which one could mention that all this seems to have been done some long time ago.



          documentclassarticle
          usepackagebraket
          begindocument
          [
          Braket b + Braketa
          ]
          enddocument


          enter image description here



          Back then they also needed no loop. ;-)






          share|improve this answer

























          • Well, this is definitely how I will do this whenever I don't have a strict whitelist of packages to adhere to.

            – Alex Reinking
            5 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/4.0/"u003ecc by-sa 4.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
          );



          );







          Alex Reinking is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f507195%2fhow-to-make-a-pipe-divided-tuple%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          4
















          I don't think you need a loop:



          enter image description here



          documentclassarticle

          begingroup
          lccode`~=`|
          lowercaseendgroup
          deftup#1="8000leftlangle#1rightrangle

          begindocument

          [
          tup b + tupa
          ]

          enddocument





          share|improve this answer

























          • Do you mind explaining how this works a little bit? It seems very cool, but I don't know how I would have ever come up with it.

            – Alex Reinking
            6 hours ago











          • @AlexReinking it just gives | an active definition that expands to ;middlevert; so you don't need any looping. The definition uses mathcode "8000 (math active) so it is only locally special within that argument and other uses of | not inside the argument are not affected.

            – David Carlisle
            6 hours ago















          4
















          I don't think you need a loop:



          enter image description here



          documentclassarticle

          begingroup
          lccode`~=`|
          lowercaseendgroup
          deftup#1="8000leftlangle#1rightrangle

          begindocument

          [
          tup b + tupa
          ]

          enddocument





          share|improve this answer

























          • Do you mind explaining how this works a little bit? It seems very cool, but I don't know how I would have ever come up with it.

            – Alex Reinking
            6 hours ago











          • @AlexReinking it just gives | an active definition that expands to ;middlevert; so you don't need any looping. The definition uses mathcode "8000 (math active) so it is only locally special within that argument and other uses of | not inside the argument are not affected.

            – David Carlisle
            6 hours ago













          4














          4










          4









          I don't think you need a loop:



          enter image description here



          documentclassarticle

          begingroup
          lccode`~=`|
          lowercaseendgroup
          deftup#1="8000leftlangle#1rightrangle

          begindocument

          [
          tup b + tupa
          ]

          enddocument





          share|improve this answer













          I don't think you need a loop:



          enter image description here



          documentclassarticle

          begingroup
          lccode`~=`|
          lowercaseendgroup
          deftup#1="8000leftlangle#1rightrangle

          begindocument

          [
          tup b + tupa
          ]

          enddocument






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 7 hours ago









          David CarlisleDavid Carlisle

          521k44 gold badges1182 silver badges1952 bronze badges




          521k44 gold badges1182 silver badges1952 bronze badges















          • Do you mind explaining how this works a little bit? It seems very cool, but I don't know how I would have ever come up with it.

            – Alex Reinking
            6 hours ago











          • @AlexReinking it just gives | an active definition that expands to ;middlevert; so you don't need any looping. The definition uses mathcode "8000 (math active) so it is only locally special within that argument and other uses of | not inside the argument are not affected.

            – David Carlisle
            6 hours ago

















          • Do you mind explaining how this works a little bit? It seems very cool, but I don't know how I would have ever come up with it.

            – Alex Reinking
            6 hours ago











          • @AlexReinking it just gives | an active definition that expands to ;middlevert; so you don't need any looping. The definition uses mathcode "8000 (math active) so it is only locally special within that argument and other uses of | not inside the argument are not affected.

            – David Carlisle
            6 hours ago
















          Do you mind explaining how this works a little bit? It seems very cool, but I don't know how I would have ever come up with it.

          – Alex Reinking
          6 hours ago





          Do you mind explaining how this works a little bit? It seems very cool, but I don't know how I would have ever come up with it.

          – Alex Reinking
          6 hours ago













          @AlexReinking it just gives | an active definition that expands to ;middlevert; so you don't need any looping. The definition uses mathcode "8000 (math active) so it is only locally special within that argument and other uses of | not inside the argument are not affected.

          – David Carlisle
          6 hours ago





          @AlexReinking it just gives | an active definition that expands to ;middlevert; so you don't need any looping. The definition uses mathcode "8000 (math active) so it is only locally special within that argument and other uses of | not inside the argument are not affected.

          – David Carlisle
          6 hours ago













          5
















          As a general rule, I recommend to avoid left and right whenever possible.



          Here's an implementation with a syntax similar to commands defined with DeclarePairedDelimiter from mathtools.



          The unadorned command uses normal size; in the optional argument big, Big, bigg or Bigg can appear. The * means using automatic sizing.



          Spaces in the mandatory argument are ignored, so tupb is the same as tup c.



          documentclassarticle
          usepackageamsmath
          usepackagexparse

          ExplSyntaxOn

          NewDocumentCommandtupsom

          IfBooleanTF#1

          tl_set:Nn l__reinking_tup_open_tl leftlangle
          tl_set:Nn l__reinking_tup_middle_tl ;
          tl_set:Nn l__reinking_tup_close_tl rightrangle


          IfNoValueTF#2

          tl_set:Nn l__reinking_tup_open_tl langle
          tl_set:Nn l__reinking_tup_middle_tl mathrel
          tl_set:Nn l__reinking_tup_close_tl rangle


          tl_set:Nn l__reinking_tup_open_tl mathopen#2langle
          tl_set:Nn l__reinking_tup_middle_tl mathrel#2
          tl_set:Nn l__reinking_tup_close_tl mathclose#2rangle


          __reinking_tup:n #3


          tl_new:N l__reinking_tup_open_tl
          tl_new:N l__reinking_tup_middle_tl
          tl_new:N l__reinking_tup_close_tl
          seq_new:N l__reinking_tup_items_seq

          cs_new_protected:Nn __reinking_tup:n

          seq_set_split:Nnn l__reinking_tup_items_seq #1
          l__reinking_tup_open_tl
          seq_use:NV l__reinking_tup_items_seq l__reinking_tup_middle_tl
          l__reinking_tup_close_tl

          cs_generate_variant:Nn seq_use:Nn NV

          ExplSyntaxOff

          begindocument

          $tupa$
          quad
          $tup[big]a$
          quad
          $tup[Big]a$
          quad
          $tup*dots$

          enddocument


          enter image description here



          A package-free version, which indiscriminately uses left, middle and right. The items are absorbed one at a time and appended to a list, then the list is executed.



          documentclassarticle
          usepackageamsmath

          makeatletter
          newcommandtup[1]%
          def@tup@list%
          @tup#1
          def@tup#1|%
          ifx@tup#1relax
          expandafter@firstoftwo
          else
          expandafter@secondoftwo
          fi
          leftlangle@tup@listrightrangle%
          ifx@tup@list@empty@tup@append#1else@tup@append;#1fi@tup%

          def@tup@append#1%
          expandafterdefexpandafter@tup@listexpandafter@tup@list#1%

          makeatother

          begindocument

          $tupa$

          $tupa$

          enddocument


          This way there's no problem with groups implicitly formed by left, middle and right.






          share|improve this answer



























          • Unfortunately, the publishing system I'm submitting to does not have xparse whitelisted.

            – Alex Reinking
            7 hours ago











          • @AlexReinking Too bad. Do you really need left, middle and right?

            – egreg
            7 hours ago












          • @AlexReinking I added a package-free version.

            – egreg
            7 hours ago











          • Perhaps ifx@tup#1 in case one uses tupaa

            – Phelype Oleinik
            6 hours ago






          • 1





            @PhelypeOleinik You're right. I opted for ifx@tup#1relax which also copes with an empty argument.

            – egreg
            6 hours ago
















          5
















          As a general rule, I recommend to avoid left and right whenever possible.



          Here's an implementation with a syntax similar to commands defined with DeclarePairedDelimiter from mathtools.



          The unadorned command uses normal size; in the optional argument big, Big, bigg or Bigg can appear. The * means using automatic sizing.



          Spaces in the mandatory argument are ignored, so tupb is the same as tup c.



          documentclassarticle
          usepackageamsmath
          usepackagexparse

          ExplSyntaxOn

          NewDocumentCommandtupsom

          IfBooleanTF#1

          tl_set:Nn l__reinking_tup_open_tl leftlangle
          tl_set:Nn l__reinking_tup_middle_tl ;
          tl_set:Nn l__reinking_tup_close_tl rightrangle


          IfNoValueTF#2

          tl_set:Nn l__reinking_tup_open_tl langle
          tl_set:Nn l__reinking_tup_middle_tl mathrel
          tl_set:Nn l__reinking_tup_close_tl rangle


          tl_set:Nn l__reinking_tup_open_tl mathopen#2langle
          tl_set:Nn l__reinking_tup_middle_tl mathrel#2
          tl_set:Nn l__reinking_tup_close_tl mathclose#2rangle


          __reinking_tup:n #3


          tl_new:N l__reinking_tup_open_tl
          tl_new:N l__reinking_tup_middle_tl
          tl_new:N l__reinking_tup_close_tl
          seq_new:N l__reinking_tup_items_seq

          cs_new_protected:Nn __reinking_tup:n

          seq_set_split:Nnn l__reinking_tup_items_seq #1
          l__reinking_tup_open_tl
          seq_use:NV l__reinking_tup_items_seq l__reinking_tup_middle_tl
          l__reinking_tup_close_tl

          cs_generate_variant:Nn seq_use:Nn NV

          ExplSyntaxOff

          begindocument

          $tupa$
          quad
          $tup[big]a$
          quad
          $tup[Big]a$
          quad
          $tup*dots$

          enddocument


          enter image description here



          A package-free version, which indiscriminately uses left, middle and right. The items are absorbed one at a time and appended to a list, then the list is executed.



          documentclassarticle
          usepackageamsmath

          makeatletter
          newcommandtup[1]%
          def@tup@list%
          @tup#1
          def@tup#1|%
          ifx@tup#1relax
          expandafter@firstoftwo
          else
          expandafter@secondoftwo
          fi
          leftlangle@tup@listrightrangle%
          ifx@tup@list@empty@tup@append#1else@tup@append;#1fi@tup%

          def@tup@append#1%
          expandafterdefexpandafter@tup@listexpandafter@tup@list#1%

          makeatother

          begindocument

          $tupa$

          $tupa$

          enddocument


          This way there's no problem with groups implicitly formed by left, middle and right.






          share|improve this answer



























          • Unfortunately, the publishing system I'm submitting to does not have xparse whitelisted.

            – Alex Reinking
            7 hours ago











          • @AlexReinking Too bad. Do you really need left, middle and right?

            – egreg
            7 hours ago












          • @AlexReinking I added a package-free version.

            – egreg
            7 hours ago











          • Perhaps ifx@tup#1 in case one uses tupaa

            – Phelype Oleinik
            6 hours ago






          • 1





            @PhelypeOleinik You're right. I opted for ifx@tup#1relax which also copes with an empty argument.

            – egreg
            6 hours ago














          5














          5










          5









          As a general rule, I recommend to avoid left and right whenever possible.



          Here's an implementation with a syntax similar to commands defined with DeclarePairedDelimiter from mathtools.



          The unadorned command uses normal size; in the optional argument big, Big, bigg or Bigg can appear. The * means using automatic sizing.



          Spaces in the mandatory argument are ignored, so tupb is the same as tup c.



          documentclassarticle
          usepackageamsmath
          usepackagexparse

          ExplSyntaxOn

          NewDocumentCommandtupsom

          IfBooleanTF#1

          tl_set:Nn l__reinking_tup_open_tl leftlangle
          tl_set:Nn l__reinking_tup_middle_tl ;
          tl_set:Nn l__reinking_tup_close_tl rightrangle


          IfNoValueTF#2

          tl_set:Nn l__reinking_tup_open_tl langle
          tl_set:Nn l__reinking_tup_middle_tl mathrel
          tl_set:Nn l__reinking_tup_close_tl rangle


          tl_set:Nn l__reinking_tup_open_tl mathopen#2langle
          tl_set:Nn l__reinking_tup_middle_tl mathrel#2
          tl_set:Nn l__reinking_tup_close_tl mathclose#2rangle


          __reinking_tup:n #3


          tl_new:N l__reinking_tup_open_tl
          tl_new:N l__reinking_tup_middle_tl
          tl_new:N l__reinking_tup_close_tl
          seq_new:N l__reinking_tup_items_seq

          cs_new_protected:Nn __reinking_tup:n

          seq_set_split:Nnn l__reinking_tup_items_seq #1
          l__reinking_tup_open_tl
          seq_use:NV l__reinking_tup_items_seq l__reinking_tup_middle_tl
          l__reinking_tup_close_tl

          cs_generate_variant:Nn seq_use:Nn NV

          ExplSyntaxOff

          begindocument

          $tupa$
          quad
          $tup[big]a$
          quad
          $tup[Big]a$
          quad
          $tup*dots$

          enddocument


          enter image description here



          A package-free version, which indiscriminately uses left, middle and right. The items are absorbed one at a time and appended to a list, then the list is executed.



          documentclassarticle
          usepackageamsmath

          makeatletter
          newcommandtup[1]%
          def@tup@list%
          @tup#1
          def@tup#1|%
          ifx@tup#1relax
          expandafter@firstoftwo
          else
          expandafter@secondoftwo
          fi
          leftlangle@tup@listrightrangle%
          ifx@tup@list@empty@tup@append#1else@tup@append;#1fi@tup%

          def@tup@append#1%
          expandafterdefexpandafter@tup@listexpandafter@tup@list#1%

          makeatother

          begindocument

          $tupa$

          $tupa$

          enddocument


          This way there's no problem with groups implicitly formed by left, middle and right.






          share|improve this answer















          As a general rule, I recommend to avoid left and right whenever possible.



          Here's an implementation with a syntax similar to commands defined with DeclarePairedDelimiter from mathtools.



          The unadorned command uses normal size; in the optional argument big, Big, bigg or Bigg can appear. The * means using automatic sizing.



          Spaces in the mandatory argument are ignored, so tupb is the same as tup c.



          documentclassarticle
          usepackageamsmath
          usepackagexparse

          ExplSyntaxOn

          NewDocumentCommandtupsom

          IfBooleanTF#1

          tl_set:Nn l__reinking_tup_open_tl leftlangle
          tl_set:Nn l__reinking_tup_middle_tl ;
          tl_set:Nn l__reinking_tup_close_tl rightrangle


          IfNoValueTF#2

          tl_set:Nn l__reinking_tup_open_tl langle
          tl_set:Nn l__reinking_tup_middle_tl mathrel
          tl_set:Nn l__reinking_tup_close_tl rangle


          tl_set:Nn l__reinking_tup_open_tl mathopen#2langle
          tl_set:Nn l__reinking_tup_middle_tl mathrel#2
          tl_set:Nn l__reinking_tup_close_tl mathclose#2rangle


          __reinking_tup:n #3


          tl_new:N l__reinking_tup_open_tl
          tl_new:N l__reinking_tup_middle_tl
          tl_new:N l__reinking_tup_close_tl
          seq_new:N l__reinking_tup_items_seq

          cs_new_protected:Nn __reinking_tup:n

          seq_set_split:Nnn l__reinking_tup_items_seq #1
          l__reinking_tup_open_tl
          seq_use:NV l__reinking_tup_items_seq l__reinking_tup_middle_tl
          l__reinking_tup_close_tl

          cs_generate_variant:Nn seq_use:Nn NV

          ExplSyntaxOff

          begindocument

          $tupa$
          quad
          $tup[big]a$
          quad
          $tup[Big]a$
          quad
          $tup*dots$

          enddocument


          enter image description here



          A package-free version, which indiscriminately uses left, middle and right. The items are absorbed one at a time and appended to a list, then the list is executed.



          documentclassarticle
          usepackageamsmath

          makeatletter
          newcommandtup[1]%
          def@tup@list%
          @tup#1
          def@tup#1|%
          ifx@tup#1relax
          expandafter@firstoftwo
          else
          expandafter@secondoftwo
          fi
          leftlangle@tup@listrightrangle%
          ifx@tup@list@empty@tup@append#1else@tup@append;#1fi@tup%

          def@tup@append#1%
          expandafterdefexpandafter@tup@listexpandafter@tup@list#1%

          makeatother

          begindocument

          $tupa$

          $tupa$

          enddocument


          This way there's no problem with groups implicitly formed by left, middle and right.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 6 hours ago

























          answered 7 hours ago









          egregegreg

          767k90 gold badges2001 silver badges3353 bronze badges




          767k90 gold badges2001 silver badges3353 bronze badges















          • Unfortunately, the publishing system I'm submitting to does not have xparse whitelisted.

            – Alex Reinking
            7 hours ago











          • @AlexReinking Too bad. Do you really need left, middle and right?

            – egreg
            7 hours ago












          • @AlexReinking I added a package-free version.

            – egreg
            7 hours ago











          • Perhaps ifx@tup#1 in case one uses tupaa

            – Phelype Oleinik
            6 hours ago






          • 1





            @PhelypeOleinik You're right. I opted for ifx@tup#1relax which also copes with an empty argument.

            – egreg
            6 hours ago


















          • Unfortunately, the publishing system I'm submitting to does not have xparse whitelisted.

            – Alex Reinking
            7 hours ago











          • @AlexReinking Too bad. Do you really need left, middle and right?

            – egreg
            7 hours ago












          • @AlexReinking I added a package-free version.

            – egreg
            7 hours ago











          • Perhaps ifx@tup#1 in case one uses tupaa

            – Phelype Oleinik
            6 hours ago






          • 1





            @PhelypeOleinik You're right. I opted for ifx@tup#1relax which also copes with an empty argument.

            – egreg
            6 hours ago

















          Unfortunately, the publishing system I'm submitting to does not have xparse whitelisted.

          – Alex Reinking
          7 hours ago





          Unfortunately, the publishing system I'm submitting to does not have xparse whitelisted.

          – Alex Reinking
          7 hours ago













          @AlexReinking Too bad. Do you really need left, middle and right?

          – egreg
          7 hours ago






          @AlexReinking Too bad. Do you really need left, middle and right?

          – egreg
          7 hours ago














          @AlexReinking I added a package-free version.

          – egreg
          7 hours ago





          @AlexReinking I added a package-free version.

          – egreg
          7 hours ago













          Perhaps ifx@tup#1 in case one uses tupaa

          – Phelype Oleinik
          6 hours ago





          Perhaps ifx@tup#1 in case one uses tupaa

          – Phelype Oleinik
          6 hours ago




          1




          1





          @PhelypeOleinik You're right. I opted for ifx@tup#1relax which also copes with an empty argument.

          – egreg
          6 hours ago






          @PhelypeOleinik You're right. I opted for ifx@tup#1relax which also copes with an empty argument.

          – egreg
          6 hours ago












          3
















          Your command was almost working. If you put more items in tup, like $tupc$ you'd see this:




          enter image description here




          it's not the first item which is left out, rather they are grouped in pairs. Your command starts with a leftlangle, which starts a "math left group" and with the @tempswa switch set to false. In the first iteration of @tuploop you do if@tempswa@sepelse@tempswatruefi which expands to @tempswatrue, meaning that no @sep is inserted now, and @tempswa is now true. The command then inserts the first item (a) and proceeds to the next iteration.



          On the second iteration, @tempswa is true and if@tempswa@sepelse@tempswatruefi expands to @sep, which inserts a middle| (the separator after a). The middle primitive will end the "math left group" started by leftlangle and will start another "math left group". However, when the first group ended, your @tempswa switch was restored to its value outside the current group, which is false! And now the command inserts b and goes to the third iteration, but now with @tempswa set to false once again.



          So your command was actually inserting <token>|<token> and then <token>|<token>, and so on, due to the end of group triggered by middle. You could circumvent this with some aftergroup magic, or simply making a gloabl assignment to the switch:



          if@tempswa@sepelseglobal@tempswatruefi


          However, as egreg said in the comment, @tempswa is supposed to be set locally only, so it would be better if you created a newififg@insertsep and then always used globalg@insertseptrue and globalg@insertsepfalse.



          And since meanwhile egreg posted a much more elaborate expl3 answer than the one-liner I would post, I'll stop here ;-)






          share|improve this answer



























          • if@tempswa should only be set locally. A different conditional to be always used globally would be preferable.

            – egreg
            7 hours ago











          • @egreg How would I know that without g_...? ;-) Thanks for pointing it out, I added a note in the answer.

            – Phelype Oleinik
            6 hours ago















          3
















          Your command was almost working. If you put more items in tup, like $tupc$ you'd see this:




          enter image description here




          it's not the first item which is left out, rather they are grouped in pairs. Your command starts with a leftlangle, which starts a "math left group" and with the @tempswa switch set to false. In the first iteration of @tuploop you do if@tempswa@sepelse@tempswatruefi which expands to @tempswatrue, meaning that no @sep is inserted now, and @tempswa is now true. The command then inserts the first item (a) and proceeds to the next iteration.



          On the second iteration, @tempswa is true and if@tempswa@sepelse@tempswatruefi expands to @sep, which inserts a middle| (the separator after a). The middle primitive will end the "math left group" started by leftlangle and will start another "math left group". However, when the first group ended, your @tempswa switch was restored to its value outside the current group, which is false! And now the command inserts b and goes to the third iteration, but now with @tempswa set to false once again.



          So your command was actually inserting <token>|<token> and then <token>|<token>, and so on, due to the end of group triggered by middle. You could circumvent this with some aftergroup magic, or simply making a gloabl assignment to the switch:



          if@tempswa@sepelseglobal@tempswatruefi


          However, as egreg said in the comment, @tempswa is supposed to be set locally only, so it would be better if you created a newififg@insertsep and then always used globalg@insertseptrue and globalg@insertsepfalse.



          And since meanwhile egreg posted a much more elaborate expl3 answer than the one-liner I would post, I'll stop here ;-)






          share|improve this answer



























          • if@tempswa should only be set locally. A different conditional to be always used globally would be preferable.

            – egreg
            7 hours ago











          • @egreg How would I know that without g_...? ;-) Thanks for pointing it out, I added a note in the answer.

            – Phelype Oleinik
            6 hours ago













          3














          3










          3









          Your command was almost working. If you put more items in tup, like $tupc$ you'd see this:




          enter image description here




          it's not the first item which is left out, rather they are grouped in pairs. Your command starts with a leftlangle, which starts a "math left group" and with the @tempswa switch set to false. In the first iteration of @tuploop you do if@tempswa@sepelse@tempswatruefi which expands to @tempswatrue, meaning that no @sep is inserted now, and @tempswa is now true. The command then inserts the first item (a) and proceeds to the next iteration.



          On the second iteration, @tempswa is true and if@tempswa@sepelse@tempswatruefi expands to @sep, which inserts a middle| (the separator after a). The middle primitive will end the "math left group" started by leftlangle and will start another "math left group". However, when the first group ended, your @tempswa switch was restored to its value outside the current group, which is false! And now the command inserts b and goes to the third iteration, but now with @tempswa set to false once again.



          So your command was actually inserting <token>|<token> and then <token>|<token>, and so on, due to the end of group triggered by middle. You could circumvent this with some aftergroup magic, or simply making a gloabl assignment to the switch:



          if@tempswa@sepelseglobal@tempswatruefi


          However, as egreg said in the comment, @tempswa is supposed to be set locally only, so it would be better if you created a newififg@insertsep and then always used globalg@insertseptrue and globalg@insertsepfalse.



          And since meanwhile egreg posted a much more elaborate expl3 answer than the one-liner I would post, I'll stop here ;-)






          share|improve this answer















          Your command was almost working. If you put more items in tup, like $tupc$ you'd see this:




          enter image description here




          it's not the first item which is left out, rather they are grouped in pairs. Your command starts with a leftlangle, which starts a "math left group" and with the @tempswa switch set to false. In the first iteration of @tuploop you do if@tempswa@sepelse@tempswatruefi which expands to @tempswatrue, meaning that no @sep is inserted now, and @tempswa is now true. The command then inserts the first item (a) and proceeds to the next iteration.



          On the second iteration, @tempswa is true and if@tempswa@sepelse@tempswatruefi expands to @sep, which inserts a middle| (the separator after a). The middle primitive will end the "math left group" started by leftlangle and will start another "math left group". However, when the first group ended, your @tempswa switch was restored to its value outside the current group, which is false! And now the command inserts b and goes to the third iteration, but now with @tempswa set to false once again.



          So your command was actually inserting <token>|<token> and then <token>|<token>, and so on, due to the end of group triggered by middle. You could circumvent this with some aftergroup magic, or simply making a gloabl assignment to the switch:



          if@tempswa@sepelseglobal@tempswatruefi


          However, as egreg said in the comment, @tempswa is supposed to be set locally only, so it would be better if you created a newififg@insertsep and then always used globalg@insertseptrue and globalg@insertsepfalse.



          And since meanwhile egreg posted a much more elaborate expl3 answer than the one-liner I would post, I'll stop here ;-)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 6 hours ago

























          answered 7 hours ago









          Phelype OleinikPhelype Oleinik

          33.5k7 gold badges56 silver badges112 bronze badges




          33.5k7 gold badges56 silver badges112 bronze badges















          • if@tempswa should only be set locally. A different conditional to be always used globally would be preferable.

            – egreg
            7 hours ago











          • @egreg How would I know that without g_...? ;-) Thanks for pointing it out, I added a note in the answer.

            – Phelype Oleinik
            6 hours ago

















          • if@tempswa should only be set locally. A different conditional to be always used globally would be preferable.

            – egreg
            7 hours ago











          • @egreg How would I know that without g_...? ;-) Thanks for pointing it out, I added a note in the answer.

            – Phelype Oleinik
            6 hours ago
















          if@tempswa should only be set locally. A different conditional to be always used globally would be preferable.

          – egreg
          7 hours ago





          if@tempswa should only be set locally. A different conditional to be always used globally would be preferable.

          – egreg
          7 hours ago













          @egreg How would I know that without g_...? ;-) Thanks for pointing it out, I added a note in the answer.

          – Phelype Oleinik
          6 hours ago





          @egreg How would I know that without g_...? ;-) Thanks for pointing it out, I added a note in the answer.

          – Phelype Oleinik
          6 hours ago











          2
















          There seems to be space for one more answer, in which one could mention that all this seems to have been done some long time ago.



          documentclassarticle
          usepackagebraket
          begindocument
          [
          Braket b + Braketa
          ]
          enddocument


          enter image description here



          Back then they also needed no loop. ;-)






          share|improve this answer

























          • Well, this is definitely how I will do this whenever I don't have a strict whitelist of packages to adhere to.

            – Alex Reinking
            5 hours ago















          2
















          There seems to be space for one more answer, in which one could mention that all this seems to have been done some long time ago.



          documentclassarticle
          usepackagebraket
          begindocument
          [
          Braket b + Braketa
          ]
          enddocument


          enter image description here



          Back then they also needed no loop. ;-)






          share|improve this answer

























          • Well, this is definitely how I will do this whenever I don't have a strict whitelist of packages to adhere to.

            – Alex Reinking
            5 hours ago













          2














          2










          2









          There seems to be space for one more answer, in which one could mention that all this seems to have been done some long time ago.



          documentclassarticle
          usepackagebraket
          begindocument
          [
          Braket b + Braketa
          ]
          enddocument


          enter image description here



          Back then they also needed no loop. ;-)






          share|improve this answer













          There seems to be space for one more answer, in which one could mention that all this seems to have been done some long time ago.



          documentclassarticle
          usepackagebraket
          begindocument
          [
          Braket b + Braketa
          ]
          enddocument


          enter image description here



          Back then they also needed no loop. ;-)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 5 hours ago









          Schrödinger's catSchrödinger's cat

          4,8517 silver badges16 bronze badges




          4,8517 silver badges16 bronze badges















          • Well, this is definitely how I will do this whenever I don't have a strict whitelist of packages to adhere to.

            – Alex Reinking
            5 hours ago

















          • Well, this is definitely how I will do this whenever I don't have a strict whitelist of packages to adhere to.

            – Alex Reinking
            5 hours ago
















          Well, this is definitely how I will do this whenever I don't have a strict whitelist of packages to adhere to.

          – Alex Reinking
          5 hours ago





          Well, this is definitely how I will do this whenever I don't have a strict whitelist of packages to adhere to.

          – Alex Reinking
          5 hours ago











          Alex Reinking is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded

















          Alex Reinking is a new contributor. Be nice, and check out our Code of Conduct.












          Alex Reinking is a new contributor. Be nice, and check out our Code of Conduct.











          Alex Reinking is a new contributor. Be nice, and check out our Code of Conduct.














          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%2f507195%2fhow-to-make-a-pipe-divided-tuple%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

          Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

          Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

          Tom Holland Mục lục Đầu đời và giáo dục | Sự nghiệp | Cuộc sống cá nhân | Phim tham gia | Giải thưởng và đề cử | Chú thích | Liên kết ngoài | Trình đơn chuyển hướngProfile“Person Details for Thomas Stanley Holland, "England and Wales Birth Registration Index, 1837-2008" — FamilySearch.org”"Meet Tom Holland... the 16-year-old star of The Impossible""Schoolboy actor Tom Holland finds himself in Oscar contention for role in tsunami drama"“Naomi Watts on the Prince William and Harry's reaction to her film about the late Princess Diana”lưu trữ"Holland and Pflueger Are West End's Two New 'Billy Elliots'""I'm so envious of my son, the movie star! British writer Dominic Holland's spent 20 years trying to crack Hollywood - but he's been beaten to it by a very unlikely rival"“Richard and Margaret Povey of Jersey, Channel Islands, UK: Information about Thomas Stanley Holland”"Tom Holland to play Billy Elliot""New Billy Elliot leaving the garage"Billy Elliot the Musical - Tom Holland - Billy"A Tale of four Billys: Tom Holland""The Feel Good Factor""Thames Christian College schoolboys join Myleene Klass for The Feelgood Factor""Government launches £600,000 arts bursaries pilot""BILLY's Chapman, Holland, Gardner & Jackson-Keen Visit Prime Minister""Elton John 'blown away' by Billy Elliot fifth birthday" (video with John's interview and fragments of Holland's performance)"First News interviews Arrietty's Tom Holland"“33rd Critics' Circle Film Awards winners”“National Board of Review Current Awards”Bản gốc"Ron Howard Whaling Tale 'In The Heart Of The Sea' Casts Tom Holland"“'Spider-Man' Finds Tom Holland to Star as New Web-Slinger”lưu trữ“Captain America: Civil War (2016)”“Film Review: ‘Captain America: Civil War’”lưu trữ“‘Captain America: Civil War’ review: Choose your own avenger”lưu trữ“The Lost City of Z reviews”“Sony Pictures and Marvel Studios Find Their 'Spider-Man' Star and Director”“‘Mary Magdalene’, ‘Current War’ & ‘Wind River’ Get 2017 Release Dates From Weinstein”“Lionsgate Unleashing Daisy Ridley & Tom Holland Starrer ‘Chaos Walking’ In Cannes”“PTA's 'Master' Leads Chicago Film Critics Nominations, UPDATED: Houston and Indiana Critics Nominations”“Nominaciones Goya 2013 Telecinco Cinema – ENG”“Jameson Empire Film Awards: Martin Freeman wins best actor for performance in The Hobbit”“34th Annual Young Artist Awards”Bản gốc“Teen Choice Awards 2016—Captain America: Civil War Leads Second Wave of Nominations”“BAFTA Film Award Nominations: ‘La La Land’ Leads Race”“Saturn Awards Nominations 2017: 'Rogue One,' 'Walking Dead' Lead”Tom HollandTom HollandTom HollandTom Hollandmedia.gettyimages.comWorldCat Identities300279794no20130442900000 0004 0355 42791085670554170004732cb16706349t(data)XX5557367