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

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

Temporarily simulate being offline programmatically

What's this constructed number's starter?

Fantasy Military Arms and Armor: the Dwarven Grand Armory

Friend is very nit picky about side comments I don't intend to be taken too seriously

1kV DC Circuit - Insulation on ground wire?

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

Can Adventure creatures always be cast from exile?

How do I delete cookies from a specific site?

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

Word for something that used to be popular but not anymore

Is Sanskrit really the mother of all languages?

Is future tense in English really a myth?

Meaning of "Right Out" in Context

What are some countries where you can be imprisoned for reading or owning a Bible?

What exactly is Apple Cider

How to measure the statistical "distance" between two frequency distributions?

"syntax error near unexpected token" after editing .bashrc

What do English-speaking kids call ice-cream on a stick?

Draw the ☣ (Biohazard Symbol)

Where on Earth is it easiest to survive in the wilderness?

Why would image resources loaded from different origins triggering HTTP authentication dialogs be harmful?

Pronounceable encrypted text

Why did Tony's Arc Reactor do this?



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
$tupc$
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
    $tupc$
    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
      $tupc$
      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
      $tupc$
      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 9 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 z + 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 tupc 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 ;middle
          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
          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*b$

          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#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
            8 hours ago











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

            – egreg
            8 hours ago












          • @AlexReinking I added a package-free version.

            – egreg
            7 hours ago











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

            – Phelype Oleinik
            7 hours ago






          • 1





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

            – egreg
            7 hours ago



















          3
















          Your command was almost working. If you put more items in tup, like $tupf$ 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
            7 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 z + 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 z + 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 z + 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 z + 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 z + 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 tupc 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 ;middle
          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
          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*b$

          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#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
            8 hours ago











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

            – egreg
            8 hours ago












          • @AlexReinking I added a package-free version.

            – egreg
            7 hours ago











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

            – Phelype Oleinik
            7 hours ago






          • 1





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

            – egreg
            7 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 tupc 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 ;middle
          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
          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*b$

          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#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
            8 hours ago











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

            – egreg
            8 hours ago












          • @AlexReinking I added a package-free version.

            – egreg
            7 hours ago











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

            – Phelype Oleinik
            7 hours ago






          • 1





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

            – egreg
            7 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 tupc 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 ;middle
          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
          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*b$

          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#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 tupc 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 ;middle
          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
          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*b$

          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#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 7 hours ago

























          answered 8 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
            8 hours ago











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

            – egreg
            8 hours ago












          • @AlexReinking I added a package-free version.

            – egreg
            7 hours ago











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

            – Phelype Oleinik
            7 hours ago






          • 1





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

            – egreg
            7 hours ago


















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

            – Alex Reinking
            8 hours ago











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

            – egreg
            8 hours ago












          • @AlexReinking I added a package-free version.

            – egreg
            7 hours ago











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

            – Phelype Oleinik
            7 hours ago






          • 1





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

            – egreg
            7 hours ago

















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

          – Alex Reinking
          8 hours ago





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

          – Alex Reinking
          8 hours ago













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

          – egreg
          8 hours ago






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

          – egreg
          8 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
          7 hours ago





          Perhaps ifx@tup#1 in case one uses tupaa

          – Phelype Oleinik
          7 hours ago




          1




          1





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

          – egreg
          7 hours ago






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

          – egreg
          7 hours ago












          3
















          Your command was almost working. If you put more items in tup, like $tupf$ 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
            7 hours ago















          3
















          Your command was almost working. If you put more items in tup, like $tupf$ 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
            7 hours ago













          3














          3










          3









          Your command was almost working. If you put more items in tup, like $tupf$ 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 $tupf$ 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 7 hours ago

























          answered 8 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
            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
            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





          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
          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
          7 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 z + 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 z + 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 z + 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 z + 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

          ParseJSON using SSJSUsing AMPscript with SSJS ActivitiesHow to resubscribe a user in Marketing cloud using SSJS?Pulling Subscriber Status from Lists using SSJSRetrieving Emails using SSJSProblem in updating DE using SSJSUsing SSJS to send single email in Marketing CloudError adding EmailSendDefinition using SSJS

          Кампала Садржај Географија Географија Историја Становништво Привреда Партнерски градови Референце Спољашње везе Мени за навигацију0°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.340°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.34МедијиПодациЗванични веб-сајту

          19. јануар Садржај Догађаји Рођења Смрти Празници и дани сећања Види још Референце Мени за навигацијуу