Problems with def

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I have created the following macros in LaTeX:



deftwomate(#1,#2,#3,#4)beginpmatrix#1&#2\#3&#4endpmatrix
defpwr(#1)^#1
deftwoclmn(#1,#2)beginpmatrix#1\#2endpmatrix


Where twomate is a 2x2 matrix, twoclmn creates a 2x1 column vector, and pwr is a command to raise the argument to the power.
However, if I try to do the following:



$$twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t) )$$


I get an error. However, if I replace the last entry with something that is not a def command:



$$twomate(3epwr(-3t),epwr(2t),-epwr(-3t),5 )$$


The document complies successfully. In addition, the following does not compile successfully:



$$twoclmn(frac625epwr(2t)-frac15tepwr(2t),-frac225epwr(2t) + frac25 t epwr(2t))$$


But the following does:



$$twoclmn(frac625e^2t-frac15te^2t,-frac225e^2t + frac25 t e^2t)$$


So the problem seems to be the nested def commands. How may I nest def commands, without the compiler complaining?










share|improve this question







New contributor




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























    up vote
    1
    down vote

    favorite












    I have created the following macros in LaTeX:



    deftwomate(#1,#2,#3,#4)beginpmatrix#1&#2\#3&#4endpmatrix
    defpwr(#1)^#1
    deftwoclmn(#1,#2)beginpmatrix#1\#2endpmatrix


    Where twomate is a 2x2 matrix, twoclmn creates a 2x1 column vector, and pwr is a command to raise the argument to the power.
    However, if I try to do the following:



    $$twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t) )$$


    I get an error. However, if I replace the last entry with something that is not a def command:



    $$twomate(3epwr(-3t),epwr(2t),-epwr(-3t),5 )$$


    The document complies successfully. In addition, the following does not compile successfully:



    $$twoclmn(frac625epwr(2t)-frac15tepwr(2t),-frac225epwr(2t) + frac25 t epwr(2t))$$


    But the following does:



    $$twoclmn(frac625e^2t-frac15te^2t,-frac225e^2t + frac25 t e^2t)$$


    So the problem seems to be the nested def commands. How may I nest def commands, without the compiler complaining?










    share|improve this question







    New contributor




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





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have created the following macros in LaTeX:



      deftwomate(#1,#2,#3,#4)beginpmatrix#1&#2\#3&#4endpmatrix
      defpwr(#1)^#1
      deftwoclmn(#1,#2)beginpmatrix#1\#2endpmatrix


      Where twomate is a 2x2 matrix, twoclmn creates a 2x1 column vector, and pwr is a command to raise the argument to the power.
      However, if I try to do the following:



      $$twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t) )$$


      I get an error. However, if I replace the last entry with something that is not a def command:



      $$twomate(3epwr(-3t),epwr(2t),-epwr(-3t),5 )$$


      The document complies successfully. In addition, the following does not compile successfully:



      $$twoclmn(frac625epwr(2t)-frac15tepwr(2t),-frac225epwr(2t) + frac25 t epwr(2t))$$


      But the following does:



      $$twoclmn(frac625e^2t-frac15te^2t,-frac225e^2t + frac25 t e^2t)$$


      So the problem seems to be the nested def commands. How may I nest def commands, without the compiler complaining?










      share|improve this question







      New contributor




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











      I have created the following macros in LaTeX:



      deftwomate(#1,#2,#3,#4)beginpmatrix#1&#2\#3&#4endpmatrix
      defpwr(#1)^#1
      deftwoclmn(#1,#2)beginpmatrix#1\#2endpmatrix


      Where twomate is a 2x2 matrix, twoclmn creates a 2x1 column vector, and pwr is a command to raise the argument to the power.
      However, if I try to do the following:



      $$twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t) )$$


      I get an error. However, if I replace the last entry with something that is not a def command:



      $$twomate(3epwr(-3t),epwr(2t),-epwr(-3t),5 )$$


      The document complies successfully. In addition, the following does not compile successfully:



      $$twoclmn(frac625epwr(2t)-frac15tepwr(2t),-frac225epwr(2t) + frac25 t epwr(2t))$$


      But the following does:



      $$twoclmn(frac625e^2t-frac15te^2t,-frac225e^2t + frac25 t e^2t)$$


      So the problem seems to be the nested def commands. How may I nest def commands, without the compiler complaining?







      math-mode macros






      share|improve this question







      New contributor




      Hossmeister 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




      Hossmeister 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






      New contributor




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









      asked 4 hours ago









      Hossmeister

      61




      61




      New contributor




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





      New contributor





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






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




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          2
          down vote













          TeX's delimited parameters parsing doesn't take nesting into account properly. So if you call twomate(3epwr(-3t), ...), the final ) for twomate isn't found at the end of that line but at the end of pwr(-3t). The improperly formed call of pwr then causes trouble.



          To hide nested calls of your commands, put them into ... groups (though this probably defeats the purpose):



          documentclassarticle
          usepackageamsmath

          deftwomate(#1,#2,#3,#4)beginpmatrix#1&#2\#3&#4endpmatrix
          defpwr(#1)^#1
          deftwoclmn(#1,#2)beginpmatrix#1\#2endpmatrix

          begindocument
          [ twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t)) ]
          enddocument


          enter image description here



          By the way, don't use $$ ... $$ for display math environments but LaTeX's or amsmath's variants like [ ... ].






          share|improve this answer





























            up vote
            2
            down vote













            You can use xparse for this job, because the r argument type takes care of nesting.



            documentclassarticle
            usepackageamsmath
            usepackagexparse

            NewDocumentCommandtwomate>SplitArgument3,r()%
            maketwomate#1%

            NewDocumentCommandmaketwomatemmmm%
            beginpmatrix#1&#2\#3&#4endpmatrix%

            NewDocumentCommandpwrr()^#1

            begindocument

            [
            twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t) )
            ]

            enddocument


            However, using () as delimiters doesn't seem a good idea. The following is as clear and behaves better with syntax coloring of front ends.



            documentclassarticle
            usepackageamsmath
            usepackagexparse

            NewDocumentCommandtwomate>SplitArgument3,m%
            maketwomate#1%

            NewDocumentCommandmaketwomatemmmm%
            beginpmatrix#1&#2\#3&#4endpmatrix%

            NewDocumentCommandpwrm^#1

            begindocument

            [
            twomate3epwr-3t,epwr2t,-epwr-3t,-2epwr2t
            ]

            enddocument


            enter image description here






            share|improve this answer



























              up vote
              1
              down vote













              Your def contains a very specific sequence defined as the parameter text:



              % 1 2 3 4 5
              deftwomate(<1>,<2>,<3>,<4>) ...
              % ^ ^ ^ ^ ^
              % │ │ │ │ │
              % │ └ comma ┘ │
              % └─── bracket ───┘


              This parameter text is matched exactly in order (almost like a first-come-first-served style) to extract the four arguments <1>, <2>, <3> and <4>. Here's how the elements are grabbed for twomate with the above notation:



              % 1 2 3 4 5
              twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
              % ^ ^ ^ ^ ^
              % │ │ │ │ │
              % │ └────── comma ────────┘ │
              % └───────────────── bracket ──────────────────┘


              It should be clear that the last bracket ) isn't properly captured for pwr. The way around it is to hide pwr(.) from twomate:



              documentclassarticle

              usepackageamsmath

              deftwomate(#1,#2,#3,#4)beginpmatrix#1&#2\#3&#4endpmatrix
              defpwr(#1)^#1

              begindocument

              [
              twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
              ]

              enddocument


              This solves the problem only temporarily. If you nest elements, you'll run into similar problems because of the parameter text pattern matching. In general, it is safer to group arguments using ....






              share|improve this answer






















                Your Answer








                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "85"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                convertImagesToLinks: false,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );






                Hossmeister 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%2f459229%2fproblems-with-def%23new-answer', 'question_page');

                );

                Post as a guest






























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                2
                down vote













                TeX's delimited parameters parsing doesn't take nesting into account properly. So if you call twomate(3epwr(-3t), ...), the final ) for twomate isn't found at the end of that line but at the end of pwr(-3t). The improperly formed call of pwr then causes trouble.



                To hide nested calls of your commands, put them into ... groups (though this probably defeats the purpose):



                documentclassarticle
                usepackageamsmath

                deftwomate(#1,#2,#3,#4)beginpmatrix#1&#2\#3&#4endpmatrix
                defpwr(#1)^#1
                deftwoclmn(#1,#2)beginpmatrix#1\#2endpmatrix

                begindocument
                [ twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t)) ]
                enddocument


                enter image description here



                By the way, don't use $$ ... $$ for display math environments but LaTeX's or amsmath's variants like [ ... ].






                share|improve this answer


























                  up vote
                  2
                  down vote













                  TeX's delimited parameters parsing doesn't take nesting into account properly. So if you call twomate(3epwr(-3t), ...), the final ) for twomate isn't found at the end of that line but at the end of pwr(-3t). The improperly formed call of pwr then causes trouble.



                  To hide nested calls of your commands, put them into ... groups (though this probably defeats the purpose):



                  documentclassarticle
                  usepackageamsmath

                  deftwomate(#1,#2,#3,#4)beginpmatrix#1&#2\#3&#4endpmatrix
                  defpwr(#1)^#1
                  deftwoclmn(#1,#2)beginpmatrix#1\#2endpmatrix

                  begindocument
                  [ twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t)) ]
                  enddocument


                  enter image description here



                  By the way, don't use $$ ... $$ for display math environments but LaTeX's or amsmath's variants like [ ... ].






                  share|improve this answer
























                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote









                    TeX's delimited parameters parsing doesn't take nesting into account properly. So if you call twomate(3epwr(-3t), ...), the final ) for twomate isn't found at the end of that line but at the end of pwr(-3t). The improperly formed call of pwr then causes trouble.



                    To hide nested calls of your commands, put them into ... groups (though this probably defeats the purpose):



                    documentclassarticle
                    usepackageamsmath

                    deftwomate(#1,#2,#3,#4)beginpmatrix#1&#2\#3&#4endpmatrix
                    defpwr(#1)^#1
                    deftwoclmn(#1,#2)beginpmatrix#1\#2endpmatrix

                    begindocument
                    [ twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t)) ]
                    enddocument


                    enter image description here



                    By the way, don't use $$ ... $$ for display math environments but LaTeX's or amsmath's variants like [ ... ].






                    share|improve this answer














                    TeX's delimited parameters parsing doesn't take nesting into account properly. So if you call twomate(3epwr(-3t), ...), the final ) for twomate isn't found at the end of that line but at the end of pwr(-3t). The improperly formed call of pwr then causes trouble.



                    To hide nested calls of your commands, put them into ... groups (though this probably defeats the purpose):



                    documentclassarticle
                    usepackageamsmath

                    deftwomate(#1,#2,#3,#4)beginpmatrix#1&#2\#3&#4endpmatrix
                    defpwr(#1)^#1
                    deftwoclmn(#1,#2)beginpmatrix#1\#2endpmatrix

                    begindocument
                    [ twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t)) ]
                    enddocument


                    enter image description here



                    By the way, don't use $$ ... $$ for display math environments but LaTeX's or amsmath's variants like [ ... ].







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 3 hours ago

























                    answered 3 hours ago









                    siracusa

                    4,26911127




                    4,26911127




















                        up vote
                        2
                        down vote













                        You can use xparse for this job, because the r argument type takes care of nesting.



                        documentclassarticle
                        usepackageamsmath
                        usepackagexparse

                        NewDocumentCommandtwomate>SplitArgument3,r()%
                        maketwomate#1%

                        NewDocumentCommandmaketwomatemmmm%
                        beginpmatrix#1&#2\#3&#4endpmatrix%

                        NewDocumentCommandpwrr()^#1

                        begindocument

                        [
                        twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t) )
                        ]

                        enddocument


                        However, using () as delimiters doesn't seem a good idea. The following is as clear and behaves better with syntax coloring of front ends.



                        documentclassarticle
                        usepackageamsmath
                        usepackagexparse

                        NewDocumentCommandtwomate>SplitArgument3,m%
                        maketwomate#1%

                        NewDocumentCommandmaketwomatemmmm%
                        beginpmatrix#1&#2\#3&#4endpmatrix%

                        NewDocumentCommandpwrm^#1

                        begindocument

                        [
                        twomate3epwr-3t,epwr2t,-epwr-3t,-2epwr2t
                        ]

                        enddocument


                        enter image description here






                        share|improve this answer
























                          up vote
                          2
                          down vote













                          You can use xparse for this job, because the r argument type takes care of nesting.



                          documentclassarticle
                          usepackageamsmath
                          usepackagexparse

                          NewDocumentCommandtwomate>SplitArgument3,r()%
                          maketwomate#1%

                          NewDocumentCommandmaketwomatemmmm%
                          beginpmatrix#1&#2\#3&#4endpmatrix%

                          NewDocumentCommandpwrr()^#1

                          begindocument

                          [
                          twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t) )
                          ]

                          enddocument


                          However, using () as delimiters doesn't seem a good idea. The following is as clear and behaves better with syntax coloring of front ends.



                          documentclassarticle
                          usepackageamsmath
                          usepackagexparse

                          NewDocumentCommandtwomate>SplitArgument3,m%
                          maketwomate#1%

                          NewDocumentCommandmaketwomatemmmm%
                          beginpmatrix#1&#2\#3&#4endpmatrix%

                          NewDocumentCommandpwrm^#1

                          begindocument

                          [
                          twomate3epwr-3t,epwr2t,-epwr-3t,-2epwr2t
                          ]

                          enddocument


                          enter image description here






                          share|improve this answer






















                            up vote
                            2
                            down vote










                            up vote
                            2
                            down vote









                            You can use xparse for this job, because the r argument type takes care of nesting.



                            documentclassarticle
                            usepackageamsmath
                            usepackagexparse

                            NewDocumentCommandtwomate>SplitArgument3,r()%
                            maketwomate#1%

                            NewDocumentCommandmaketwomatemmmm%
                            beginpmatrix#1&#2\#3&#4endpmatrix%

                            NewDocumentCommandpwrr()^#1

                            begindocument

                            [
                            twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t) )
                            ]

                            enddocument


                            However, using () as delimiters doesn't seem a good idea. The following is as clear and behaves better with syntax coloring of front ends.



                            documentclassarticle
                            usepackageamsmath
                            usepackagexparse

                            NewDocumentCommandtwomate>SplitArgument3,m%
                            maketwomate#1%

                            NewDocumentCommandmaketwomatemmmm%
                            beginpmatrix#1&#2\#3&#4endpmatrix%

                            NewDocumentCommandpwrm^#1

                            begindocument

                            [
                            twomate3epwr-3t,epwr2t,-epwr-3t,-2epwr2t
                            ]

                            enddocument


                            enter image description here






                            share|improve this answer












                            You can use xparse for this job, because the r argument type takes care of nesting.



                            documentclassarticle
                            usepackageamsmath
                            usepackagexparse

                            NewDocumentCommandtwomate>SplitArgument3,r()%
                            maketwomate#1%

                            NewDocumentCommandmaketwomatemmmm%
                            beginpmatrix#1&#2\#3&#4endpmatrix%

                            NewDocumentCommandpwrr()^#1

                            begindocument

                            [
                            twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t) )
                            ]

                            enddocument


                            However, using () as delimiters doesn't seem a good idea. The following is as clear and behaves better with syntax coloring of front ends.



                            documentclassarticle
                            usepackageamsmath
                            usepackagexparse

                            NewDocumentCommandtwomate>SplitArgument3,m%
                            maketwomate#1%

                            NewDocumentCommandmaketwomatemmmm%
                            beginpmatrix#1&#2\#3&#4endpmatrix%

                            NewDocumentCommandpwrm^#1

                            begindocument

                            [
                            twomate3epwr-3t,epwr2t,-epwr-3t,-2epwr2t
                            ]

                            enddocument


                            enter image description here







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 2 hours ago









                            egreg

                            696k8518473104




                            696k8518473104




















                                up vote
                                1
                                down vote













                                Your def contains a very specific sequence defined as the parameter text:



                                % 1 2 3 4 5
                                deftwomate(<1>,<2>,<3>,<4>) ...
                                % ^ ^ ^ ^ ^
                                % │ │ │ │ │
                                % │ └ comma ┘ │
                                % └─── bracket ───┘


                                This parameter text is matched exactly in order (almost like a first-come-first-served style) to extract the four arguments <1>, <2>, <3> and <4>. Here's how the elements are grabbed for twomate with the above notation:



                                % 1 2 3 4 5
                                twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
                                % ^ ^ ^ ^ ^
                                % │ │ │ │ │
                                % │ └────── comma ────────┘ │
                                % └───────────────── bracket ──────────────────┘


                                It should be clear that the last bracket ) isn't properly captured for pwr. The way around it is to hide pwr(.) from twomate:



                                documentclassarticle

                                usepackageamsmath

                                deftwomate(#1,#2,#3,#4)beginpmatrix#1&#2\#3&#4endpmatrix
                                defpwr(#1)^#1

                                begindocument

                                [
                                twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
                                ]

                                enddocument


                                This solves the problem only temporarily. If you nest elements, you'll run into similar problems because of the parameter text pattern matching. In general, it is safer to group arguments using ....






                                share|improve this answer


























                                  up vote
                                  1
                                  down vote













                                  Your def contains a very specific sequence defined as the parameter text:



                                  % 1 2 3 4 5
                                  deftwomate(<1>,<2>,<3>,<4>) ...
                                  % ^ ^ ^ ^ ^
                                  % │ │ │ │ │
                                  % │ └ comma ┘ │
                                  % └─── bracket ───┘


                                  This parameter text is matched exactly in order (almost like a first-come-first-served style) to extract the four arguments <1>, <2>, <3> and <4>. Here's how the elements are grabbed for twomate with the above notation:



                                  % 1 2 3 4 5
                                  twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
                                  % ^ ^ ^ ^ ^
                                  % │ │ │ │ │
                                  % │ └────── comma ────────┘ │
                                  % └───────────────── bracket ──────────────────┘


                                  It should be clear that the last bracket ) isn't properly captured for pwr. The way around it is to hide pwr(.) from twomate:



                                  documentclassarticle

                                  usepackageamsmath

                                  deftwomate(#1,#2,#3,#4)beginpmatrix#1&#2\#3&#4endpmatrix
                                  defpwr(#1)^#1

                                  begindocument

                                  [
                                  twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
                                  ]

                                  enddocument


                                  This solves the problem only temporarily. If you nest elements, you'll run into similar problems because of the parameter text pattern matching. In general, it is safer to group arguments using ....






                                  share|improve this answer
























                                    up vote
                                    1
                                    down vote










                                    up vote
                                    1
                                    down vote









                                    Your def contains a very specific sequence defined as the parameter text:



                                    % 1 2 3 4 5
                                    deftwomate(<1>,<2>,<3>,<4>) ...
                                    % ^ ^ ^ ^ ^
                                    % │ │ │ │ │
                                    % │ └ comma ┘ │
                                    % └─── bracket ───┘


                                    This parameter text is matched exactly in order (almost like a first-come-first-served style) to extract the four arguments <1>, <2>, <3> and <4>. Here's how the elements are grabbed for twomate with the above notation:



                                    % 1 2 3 4 5
                                    twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
                                    % ^ ^ ^ ^ ^
                                    % │ │ │ │ │
                                    % │ └────── comma ────────┘ │
                                    % └───────────────── bracket ──────────────────┘


                                    It should be clear that the last bracket ) isn't properly captured for pwr. The way around it is to hide pwr(.) from twomate:



                                    documentclassarticle

                                    usepackageamsmath

                                    deftwomate(#1,#2,#3,#4)beginpmatrix#1&#2\#3&#4endpmatrix
                                    defpwr(#1)^#1

                                    begindocument

                                    [
                                    twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
                                    ]

                                    enddocument


                                    This solves the problem only temporarily. If you nest elements, you'll run into similar problems because of the parameter text pattern matching. In general, it is safer to group arguments using ....






                                    share|improve this answer














                                    Your def contains a very specific sequence defined as the parameter text:



                                    % 1 2 3 4 5
                                    deftwomate(<1>,<2>,<3>,<4>) ...
                                    % ^ ^ ^ ^ ^
                                    % │ │ │ │ │
                                    % │ └ comma ┘ │
                                    % └─── bracket ───┘


                                    This parameter text is matched exactly in order (almost like a first-come-first-served style) to extract the four arguments <1>, <2>, <3> and <4>. Here's how the elements are grabbed for twomate with the above notation:



                                    % 1 2 3 4 5
                                    twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
                                    % ^ ^ ^ ^ ^
                                    % │ │ │ │ │
                                    % │ └────── comma ────────┘ │
                                    % └───────────────── bracket ──────────────────┘


                                    It should be clear that the last bracket ) isn't properly captured for pwr. The way around it is to hide pwr(.) from twomate:



                                    documentclassarticle

                                    usepackageamsmath

                                    deftwomate(#1,#2,#3,#4)beginpmatrix#1&#2\#3&#4endpmatrix
                                    defpwr(#1)^#1

                                    begindocument

                                    [
                                    twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
                                    ]

                                    enddocument


                                    This solves the problem only temporarily. If you nest elements, you'll run into similar problems because of the parameter text pattern matching. In general, it is safer to group arguments using ....







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited 3 hours ago

























                                    answered 3 hours ago









                                    Werner

                                    429k589401618




                                    429k589401618




















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









                                         

                                        draft saved


                                        draft discarded


















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












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











                                        Hossmeister 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%2f459229%2fproblems-with-def%23new-answer', 'question_page');

                                        );

                                        Post as a guest













































































                                        Comments

                                        Popular posts from this blog

                                        What does second last employer means? [closed]

                                        Installing NextGIS Connect into QGIS 3?

                                        One-line joke