Transpose a matrix and parenthesis

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












1















I would like to define a command transp having eventually one argument : the name of the matrix and finally two outputs.




  1. transpA is the matrix A^T between parenthesis,


  2. transp A is just the matrix A^T.

I tried this command :



newcommandtransp[1]
ifstrempty#1^texttbfT ^texttbfT left( #1 right)


but to print the transpose symbol I have to write transp. Can I modify the previous command in order to just write transp (as mentioned in 2.) ?










share|improve this question

















  • 2





    Usually foo A and fooA are the same for a macro foo taking an argument. So this is not easily done and would go against the normal behaviour (I don't want to say good practice, because I'm led to believe that it would be better practice to use braces even for one-token arguments). I think I saw a related question a while ago, but I can't find it now and it might have been about something else entirely.

    – moewe
    Feb 28 at 11:35
















1















I would like to define a command transp having eventually one argument : the name of the matrix and finally two outputs.




  1. transpA is the matrix A^T between parenthesis,


  2. transp A is just the matrix A^T.

I tried this command :



newcommandtransp[1]
ifstrempty#1^texttbfT ^texttbfT left( #1 right)


but to print the transpose symbol I have to write transp. Can I modify the previous command in order to just write transp (as mentioned in 2.) ?










share|improve this question

















  • 2





    Usually foo A and fooA are the same for a macro foo taking an argument. So this is not easily done and would go against the normal behaviour (I don't want to say good practice, because I'm led to believe that it would be better practice to use braces even for one-token arguments). I think I saw a related question a while ago, but I can't find it now and it might have been about something else entirely.

    – moewe
    Feb 28 at 11:35














1












1








1








I would like to define a command transp having eventually one argument : the name of the matrix and finally two outputs.




  1. transpA is the matrix A^T between parenthesis,


  2. transp A is just the matrix A^T.

I tried this command :



newcommandtransp[1]
ifstrempty#1^texttbfT ^texttbfT left( #1 right)


but to print the transpose symbol I have to write transp. Can I modify the previous command in order to just write transp (as mentioned in 2.) ?










share|improve this question














I would like to define a command transp having eventually one argument : the name of the matrix and finally two outputs.




  1. transpA is the matrix A^T between parenthesis,


  2. transp A is just the matrix A^T.

I tried this command :



newcommandtransp[1]
ifstrempty#1^texttbfT ^texttbfT left( #1 right)


but to print the transpose symbol I have to write transp. Can I modify the previous command in order to just write transp (as mentioned in 2.) ?







macros conditionals math-operators






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 28 at 11:33









jowe_19jowe_19

7510




7510







  • 2





    Usually foo A and fooA are the same for a macro foo taking an argument. So this is not easily done and would go against the normal behaviour (I don't want to say good practice, because I'm led to believe that it would be better practice to use braces even for one-token arguments). I think I saw a related question a while ago, but I can't find it now and it might have been about something else entirely.

    – moewe
    Feb 28 at 11:35













  • 2





    Usually foo A and fooA are the same for a macro foo taking an argument. So this is not easily done and would go against the normal behaviour (I don't want to say good practice, because I'm led to believe that it would be better practice to use braces even for one-token arguments). I think I saw a related question a while ago, but I can't find it now and it might have been about something else entirely.

    – moewe
    Feb 28 at 11:35








2




2





Usually foo A and fooA are the same for a macro foo taking an argument. So this is not easily done and would go against the normal behaviour (I don't want to say good practice, because I'm led to believe that it would be better practice to use braces even for one-token arguments). I think I saw a related question a while ago, but I can't find it now and it might have been about something else entirely.

– moewe
Feb 28 at 11:35






Usually foo A and fooA are the same for a macro foo taking an argument. So this is not easily done and would go against the normal behaviour (I don't want to say good practice, because I'm led to believe that it would be better practice to use braces even for one-token arguments). I think I saw a related question a while ago, but I can't find it now and it might have been about something else entirely.

– moewe
Feb 28 at 11:35











2 Answers
2






active

oldest

votes


















5














According to the standard TeX syntax, transpA and transp A are completely equivalent.



You might do in the following way:



documentclassarticle
usepackageamsmath

makeatletter
DeclareRobustCommandtransp%
@ifnextcharbgrouptransp@parentransp@simple

newcommandtransp@paren[1](#1)^T
newcommandtransp@simple[1]#1^T
makeatother

begindocument

$transp A+transpB+C$

enddocument


but I would avoid it, because it's confusing.



enter image description here



I find the following much better. You explicitly mark where you want parentheses by adding *.



documentclassarticle
usepackageamsmath
usepackagexparse

NewDocumentCommandtranspsm%
IfBooleanTF#1(#2)^T#2^T%


begindocument

$transpA+transp*B+C$

enddocument





share|improve this answer






























    5














    The following seems to work, but I doubt it is a good idea in general. Usually foo A and foo A give the same result for macros with one argument and the braces are needed in case the argument consists of more than one token. Indeed I would say that it is good practice to use braces for mandatory arguments even if they enclose only one token.



    Note that transp without braces can only accept one token as its argument, so transp A+B is transp A and +B. In particular then, transp mathbfA dies horribly.



    documentclassarticle
    usepackageamsmath

    makeatletter
    newcommand*transp@nb[1]#1^T
    newcommand*transp@br[1](#1)^T
    newcommandtransp
    protecteddeftransp%
    @ifnextcharbgroup
    transp@br
    transp@nb
    makeatother

    begindocument
    beginalign*
    transp A \
    transpA
    endalign*
    enddocument


    A^T//(A)^T



    A starred variant would be more common (see also egreg's answer)



    documentclassarticle
    usepackageamsmath

    makeatletter
    newcommand*transp@nb[1]#1^T
    newcommand*transp@br[1](#1)^T
    newcommandtransp
    protecteddeftransp%
    @ifstar
    transp@br
    transp@nb
    makeatother

    begindocument
    beginalign*
    transpA \
    transp*A
    endalign*
    enddocument


    but you could also use an optional argument (p for parentheses, b for brackets)



    documentclassarticle
    usepackageamsmath

    makeatletter
    newcommandtransp[2]%
    if#1p
    (#2)
    else
    if#1b
    [A]
    else
    A
    fi
    fi^T

    makeatother

    begindocument
    beginalign*
    transpA \
    transp[b]A
    endalign*
    enddocument





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



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f477114%2ftranspose-a-matrix-and-parenthesis%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      5














      According to the standard TeX syntax, transpA and transp A are completely equivalent.



      You might do in the following way:



      documentclassarticle
      usepackageamsmath

      makeatletter
      DeclareRobustCommandtransp%
      @ifnextcharbgrouptransp@parentransp@simple

      newcommandtransp@paren[1](#1)^T
      newcommandtransp@simple[1]#1^T
      makeatother

      begindocument

      $transp A+transpB+C$

      enddocument


      but I would avoid it, because it's confusing.



      enter image description here



      I find the following much better. You explicitly mark where you want parentheses by adding *.



      documentclassarticle
      usepackageamsmath
      usepackagexparse

      NewDocumentCommandtranspsm%
      IfBooleanTF#1(#2)^T#2^T%


      begindocument

      $transpA+transp*B+C$

      enddocument





      share|improve this answer



























        5














        According to the standard TeX syntax, transpA and transp A are completely equivalent.



        You might do in the following way:



        documentclassarticle
        usepackageamsmath

        makeatletter
        DeclareRobustCommandtransp%
        @ifnextcharbgrouptransp@parentransp@simple

        newcommandtransp@paren[1](#1)^T
        newcommandtransp@simple[1]#1^T
        makeatother

        begindocument

        $transp A+transpB+C$

        enddocument


        but I would avoid it, because it's confusing.



        enter image description here



        I find the following much better. You explicitly mark where you want parentheses by adding *.



        documentclassarticle
        usepackageamsmath
        usepackagexparse

        NewDocumentCommandtranspsm%
        IfBooleanTF#1(#2)^T#2^T%


        begindocument

        $transpA+transp*B+C$

        enddocument





        share|improve this answer

























          5












          5








          5







          According to the standard TeX syntax, transpA and transp A are completely equivalent.



          You might do in the following way:



          documentclassarticle
          usepackageamsmath

          makeatletter
          DeclareRobustCommandtransp%
          @ifnextcharbgrouptransp@parentransp@simple

          newcommandtransp@paren[1](#1)^T
          newcommandtransp@simple[1]#1^T
          makeatother

          begindocument

          $transp A+transpB+C$

          enddocument


          but I would avoid it, because it's confusing.



          enter image description here



          I find the following much better. You explicitly mark where you want parentheses by adding *.



          documentclassarticle
          usepackageamsmath
          usepackagexparse

          NewDocumentCommandtranspsm%
          IfBooleanTF#1(#2)^T#2^T%


          begindocument

          $transpA+transp*B+C$

          enddocument





          share|improve this answer













          According to the standard TeX syntax, transpA and transp A are completely equivalent.



          You might do in the following way:



          documentclassarticle
          usepackageamsmath

          makeatletter
          DeclareRobustCommandtransp%
          @ifnextcharbgrouptransp@parentransp@simple

          newcommandtransp@paren[1](#1)^T
          newcommandtransp@simple[1]#1^T
          makeatother

          begindocument

          $transp A+transpB+C$

          enddocument


          but I would avoid it, because it's confusing.



          enter image description here



          I find the following much better. You explicitly mark where you want parentheses by adding *.



          documentclassarticle
          usepackageamsmath
          usepackagexparse

          NewDocumentCommandtranspsm%
          IfBooleanTF#1(#2)^T#2^T%


          begindocument

          $transpA+transp*B+C$

          enddocument






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 28 at 11:44









          egregegreg

          729k8819273240




          729k8819273240





















              5














              The following seems to work, but I doubt it is a good idea in general. Usually foo A and foo A give the same result for macros with one argument and the braces are needed in case the argument consists of more than one token. Indeed I would say that it is good practice to use braces for mandatory arguments even if they enclose only one token.



              Note that transp without braces can only accept one token as its argument, so transp A+B is transp A and +B. In particular then, transp mathbfA dies horribly.



              documentclassarticle
              usepackageamsmath

              makeatletter
              newcommand*transp@nb[1]#1^T
              newcommand*transp@br[1](#1)^T
              newcommandtransp
              protecteddeftransp%
              @ifnextcharbgroup
              transp@br
              transp@nb
              makeatother

              begindocument
              beginalign*
              transp A \
              transpA
              endalign*
              enddocument


              A^T//(A)^T



              A starred variant would be more common (see also egreg's answer)



              documentclassarticle
              usepackageamsmath

              makeatletter
              newcommand*transp@nb[1]#1^T
              newcommand*transp@br[1](#1)^T
              newcommandtransp
              protecteddeftransp%
              @ifstar
              transp@br
              transp@nb
              makeatother

              begindocument
              beginalign*
              transpA \
              transp*A
              endalign*
              enddocument


              but you could also use an optional argument (p for parentheses, b for brackets)



              documentclassarticle
              usepackageamsmath

              makeatletter
              newcommandtransp[2]%
              if#1p
              (#2)
              else
              if#1b
              [A]
              else
              A
              fi
              fi^T

              makeatother

              begindocument
              beginalign*
              transpA \
              transp[b]A
              endalign*
              enddocument





              share|improve this answer





























                5














                The following seems to work, but I doubt it is a good idea in general. Usually foo A and foo A give the same result for macros with one argument and the braces are needed in case the argument consists of more than one token. Indeed I would say that it is good practice to use braces for mandatory arguments even if they enclose only one token.



                Note that transp without braces can only accept one token as its argument, so transp A+B is transp A and +B. In particular then, transp mathbfA dies horribly.



                documentclassarticle
                usepackageamsmath

                makeatletter
                newcommand*transp@nb[1]#1^T
                newcommand*transp@br[1](#1)^T
                newcommandtransp
                protecteddeftransp%
                @ifnextcharbgroup
                transp@br
                transp@nb
                makeatother

                begindocument
                beginalign*
                transp A \
                transpA
                endalign*
                enddocument


                A^T//(A)^T



                A starred variant would be more common (see also egreg's answer)



                documentclassarticle
                usepackageamsmath

                makeatletter
                newcommand*transp@nb[1]#1^T
                newcommand*transp@br[1](#1)^T
                newcommandtransp
                protecteddeftransp%
                @ifstar
                transp@br
                transp@nb
                makeatother

                begindocument
                beginalign*
                transpA \
                transp*A
                endalign*
                enddocument


                but you could also use an optional argument (p for parentheses, b for brackets)



                documentclassarticle
                usepackageamsmath

                makeatletter
                newcommandtransp[2]%
                if#1p
                (#2)
                else
                if#1b
                [A]
                else
                A
                fi
                fi^T

                makeatother

                begindocument
                beginalign*
                transpA \
                transp[b]A
                endalign*
                enddocument





                share|improve this answer



























                  5












                  5








                  5







                  The following seems to work, but I doubt it is a good idea in general. Usually foo A and foo A give the same result for macros with one argument and the braces are needed in case the argument consists of more than one token. Indeed I would say that it is good practice to use braces for mandatory arguments even if they enclose only one token.



                  Note that transp without braces can only accept one token as its argument, so transp A+B is transp A and +B. In particular then, transp mathbfA dies horribly.



                  documentclassarticle
                  usepackageamsmath

                  makeatletter
                  newcommand*transp@nb[1]#1^T
                  newcommand*transp@br[1](#1)^T
                  newcommandtransp
                  protecteddeftransp%
                  @ifnextcharbgroup
                  transp@br
                  transp@nb
                  makeatother

                  begindocument
                  beginalign*
                  transp A \
                  transpA
                  endalign*
                  enddocument


                  A^T//(A)^T



                  A starred variant would be more common (see also egreg's answer)



                  documentclassarticle
                  usepackageamsmath

                  makeatletter
                  newcommand*transp@nb[1]#1^T
                  newcommand*transp@br[1](#1)^T
                  newcommandtransp
                  protecteddeftransp%
                  @ifstar
                  transp@br
                  transp@nb
                  makeatother

                  begindocument
                  beginalign*
                  transpA \
                  transp*A
                  endalign*
                  enddocument


                  but you could also use an optional argument (p for parentheses, b for brackets)



                  documentclassarticle
                  usepackageamsmath

                  makeatletter
                  newcommandtransp[2]%
                  if#1p
                  (#2)
                  else
                  if#1b
                  [A]
                  else
                  A
                  fi
                  fi^T

                  makeatother

                  begindocument
                  beginalign*
                  transpA \
                  transp[b]A
                  endalign*
                  enddocument





                  share|improve this answer















                  The following seems to work, but I doubt it is a good idea in general. Usually foo A and foo A give the same result for macros with one argument and the braces are needed in case the argument consists of more than one token. Indeed I would say that it is good practice to use braces for mandatory arguments even if they enclose only one token.



                  Note that transp without braces can only accept one token as its argument, so transp A+B is transp A and +B. In particular then, transp mathbfA dies horribly.



                  documentclassarticle
                  usepackageamsmath

                  makeatletter
                  newcommand*transp@nb[1]#1^T
                  newcommand*transp@br[1](#1)^T
                  newcommandtransp
                  protecteddeftransp%
                  @ifnextcharbgroup
                  transp@br
                  transp@nb
                  makeatother

                  begindocument
                  beginalign*
                  transp A \
                  transpA
                  endalign*
                  enddocument


                  A^T//(A)^T



                  A starred variant would be more common (see also egreg's answer)



                  documentclassarticle
                  usepackageamsmath

                  makeatletter
                  newcommand*transp@nb[1]#1^T
                  newcommand*transp@br[1](#1)^T
                  newcommandtransp
                  protecteddeftransp%
                  @ifstar
                  transp@br
                  transp@nb
                  makeatother

                  begindocument
                  beginalign*
                  transpA \
                  transp*A
                  endalign*
                  enddocument


                  but you could also use an optional argument (p for parentheses, b for brackets)



                  documentclassarticle
                  usepackageamsmath

                  makeatletter
                  newcommandtransp[2]%
                  if#1p
                  (#2)
                  else
                  if#1b
                  [A]
                  else
                  A
                  fi
                  fi^T

                  makeatother

                  begindocument
                  beginalign*
                  transpA \
                  transp[b]A
                  endalign*
                  enddocument






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Feb 28 at 11:54

























                  answered Feb 28 at 11:44









                  moewemoewe

                  95.1k10115358




                  95.1k10115358



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f477114%2ftranspose-a-matrix-and-parenthesis%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

                      Peggy Mitchell

                      Palaiologos

                      The Forum (Inglewood, California)