Transpose a matrix and parenthesisWhat is the difference between empty and @empty?Redefine marginpar with...

What incentives do banks have to gather up loans into pools (backed by Ginnie Mae)and selling them?

A starship is travelling at 0.9c and collides with a small rock. Will it leave a clean hole through, or will more happen?

Why did Luke use his left hand to shoot?

Dilemma of explaining to interviewer that he is the reason for declining second interview

In Linux what happens if 1000 files in a directory are moved to another location while another 300 files were added to the source directory?

How can i do a custom maintenance message on magento 2.2.4

I will be going to Sweden on business purpose .Can I visit London from Sweden and how much UK visa will cost?

What is the most fuel efficient way out of the Solar System?

Removing disk while game is suspended

How did Ancient Greek 'πυρ' become English 'fire?'

Why is Agricola named as such?

How can I get my players to come to the game session after agreeing to a date?

Concatenation of fieldvalue and fieldname (handling of NULL)

What is the difference between rolling more dice versus fewer dice?

Why was Lupin comfortable with saying Voldemort's name?

Is a new Boolean field better than a null reference when a value can be meaningfully absent?

Am I a Rude Number?

The use of the spellings -zz- vs. -z-

Why would space fleets be aligned?

What are career options for big-picture thinkers with no experience?

Why is it that Bernie Sanders is always called a "socialist"?

Advice for a new journal editor

Why is working on the same position for more than 15 years not a red flag?

Why are the books in the Game of Thrones citadel library shelved spine inwards?



Transpose a matrix and parenthesis


What is the difference between empty and @empty?Redefine marginpar with renewcommandRead command with varying input argumentsAsymetric behaviour in user command with conditionalsName separators, if condition for same commandnewcommand with optional multi-line argument and implicit itemize environmentDefining a command that scans every arguments' macro “looking for” a tokenUsing fully expanded result as a simple string (with citet and IfSubStr)Define a new command with parameters inside newcommandHow to avoid using curly braces when placing a DeclareMathOperator command in subscript or superscript, while preserving spacing?













1















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





  1. transp{A} is the matrix A^T between parenthesis,


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


I tried this command :



newcommand{transp}[1]{
ifstrempty{#1}{{}^{text{tbf{T}}} }{{}^{text{tbf{T}}} 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


















  • 1





    Usually foo A and foo{A} 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
    1 hour ago


















1















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





  1. transp{A} is the matrix A^T between parenthesis,


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


I tried this command :



newcommand{transp}[1]{
ifstrempty{#1}{{}^{text{tbf{T}}} }{{}^{text{tbf{T}}} 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


















  • 1





    Usually foo A and foo{A} 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
    1 hour ago
















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. transp{A} is the matrix A^T between parenthesis,


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


I tried this command :



newcommand{transp}[1]{
ifstrempty{#1}{{}^{text{tbf{T}}} }{{}^{text{tbf{T}}} 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. transp{A} is the matrix A^T between parenthesis,


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


I tried this command :



newcommand{transp}[1]{
ifstrempty{#1}{{}^{text{tbf{T}}} }{{}^{text{tbf{T}}} 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 1 hour ago









jowe_19jowe_19

6510




6510








  • 1





    Usually foo A and foo{A} 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
    1 hour ago
















  • 1





    Usually foo A and foo{A} 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
    1 hour ago










1




1





Usually foo A and foo{A} 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
1 hour ago







Usually foo A and foo{A} 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
1 hour ago












2 Answers
2






active

oldest

votes


















4














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



You might do in the following way:



documentclass{article}
usepackage{amsmath}

makeatletter
DeclareRobustCommand{transp}{%
@ifnextcharbgrouptransp@parentransp@simple
}
newcommand{transp@paren}[1]{(#1)^{T}}
newcommand{transp@simple}[1]{#1^{T}}
makeatother

begin{document}

$transp A+transp{B+C}$

end{document}


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 *.



documentclass{article}
usepackage{amsmath}
usepackage{xparse}

NewDocumentCommand{transp}{sm}{%
IfBooleanTF{#1}{(#2)^{T}}{#2^{T}}%
}

begin{document}

$transp{A}+transp*{B+C}$

end{document}





share|improve this answer































    3














    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 mathbf{A} dies horribly.



    documentclass{article}
    usepackage{amsmath}

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

    begin{document}
    begin{align*}
    transp A \
    transp{A}
    end{align*}
    end{document}


    A^T//(A)^T



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



    documentclass{article}
    usepackage{amsmath}

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

    begin{document}
    begin{align*}
    transp{A} \
    transp*{A}
    end{align*}
    end{document}


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



    documentclass{article}
    usepackage{amsmath}

    makeatletter
    newcommand{transp}[2][]{%
    if#1p
    (#2)
    else
    if#1b
    [A]
    else
    A
    fi
    fi^{T}
    }
    makeatother

    begin{document}
    begin{align*}
    transp{A} \
    transp[b]{A}
    end{align*}
    end{document}





    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









      4














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



      You might do in the following way:



      documentclass{article}
      usepackage{amsmath}

      makeatletter
      DeclareRobustCommand{transp}{%
      @ifnextcharbgrouptransp@parentransp@simple
      }
      newcommand{transp@paren}[1]{(#1)^{T}}
      newcommand{transp@simple}[1]{#1^{T}}
      makeatother

      begin{document}

      $transp A+transp{B+C}$

      end{document}


      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 *.



      documentclass{article}
      usepackage{amsmath}
      usepackage{xparse}

      NewDocumentCommand{transp}{sm}{%
      IfBooleanTF{#1}{(#2)^{T}}{#2^{T}}%
      }

      begin{document}

      $transp{A}+transp*{B+C}$

      end{document}





      share|improve this answer




























        4














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



        You might do in the following way:



        documentclass{article}
        usepackage{amsmath}

        makeatletter
        DeclareRobustCommand{transp}{%
        @ifnextcharbgrouptransp@parentransp@simple
        }
        newcommand{transp@paren}[1]{(#1)^{T}}
        newcommand{transp@simple}[1]{#1^{T}}
        makeatother

        begin{document}

        $transp A+transp{B+C}$

        end{document}


        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 *.



        documentclass{article}
        usepackage{amsmath}
        usepackage{xparse}

        NewDocumentCommand{transp}{sm}{%
        IfBooleanTF{#1}{(#2)^{T}}{#2^{T}}%
        }

        begin{document}

        $transp{A}+transp*{B+C}$

        end{document}





        share|improve this answer


























          4












          4








          4







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



          You might do in the following way:



          documentclass{article}
          usepackage{amsmath}

          makeatletter
          DeclareRobustCommand{transp}{%
          @ifnextcharbgrouptransp@parentransp@simple
          }
          newcommand{transp@paren}[1]{(#1)^{T}}
          newcommand{transp@simple}[1]{#1^{T}}
          makeatother

          begin{document}

          $transp A+transp{B+C}$

          end{document}


          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 *.



          documentclass{article}
          usepackage{amsmath}
          usepackage{xparse}

          NewDocumentCommand{transp}{sm}{%
          IfBooleanTF{#1}{(#2)^{T}}{#2^{T}}%
          }

          begin{document}

          $transp{A}+transp*{B+C}$

          end{document}





          share|improve this answer













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



          You might do in the following way:



          documentclass{article}
          usepackage{amsmath}

          makeatletter
          DeclareRobustCommand{transp}{%
          @ifnextcharbgrouptransp@parentransp@simple
          }
          newcommand{transp@paren}[1]{(#1)^{T}}
          newcommand{transp@simple}[1]{#1^{T}}
          makeatother

          begin{document}

          $transp A+transp{B+C}$

          end{document}


          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 *.



          documentclass{article}
          usepackage{amsmath}
          usepackage{xparse}

          NewDocumentCommand{transp}{sm}{%
          IfBooleanTF{#1}{(#2)^{T}}{#2^{T}}%
          }

          begin{document}

          $transp{A}+transp*{B+C}$

          end{document}






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 1 hour ago









          egregegreg

          723k8719163219




          723k8719163219























              3














              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 mathbf{A} dies horribly.



              documentclass{article}
              usepackage{amsmath}

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

              begin{document}
              begin{align*}
              transp A \
              transp{A}
              end{align*}
              end{document}


              A^T//(A)^T



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



              documentclass{article}
              usepackage{amsmath}

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

              begin{document}
              begin{align*}
              transp{A} \
              transp*{A}
              end{align*}
              end{document}


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



              documentclass{article}
              usepackage{amsmath}

              makeatletter
              newcommand{transp}[2][]{%
              if#1p
              (#2)
              else
              if#1b
              [A]
              else
              A
              fi
              fi^{T}
              }
              makeatother

              begin{document}
              begin{align*}
              transp{A} \
              transp[b]{A}
              end{align*}
              end{document}





              share|improve this answer






























                3














                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 mathbf{A} dies horribly.



                documentclass{article}
                usepackage{amsmath}

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

                begin{document}
                begin{align*}
                transp A \
                transp{A}
                end{align*}
                end{document}


                A^T//(A)^T



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



                documentclass{article}
                usepackage{amsmath}

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

                begin{document}
                begin{align*}
                transp{A} \
                transp*{A}
                end{align*}
                end{document}


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



                documentclass{article}
                usepackage{amsmath}

                makeatletter
                newcommand{transp}[2][]{%
                if#1p
                (#2)
                else
                if#1b
                [A]
                else
                A
                fi
                fi^{T}
                }
                makeatother

                begin{document}
                begin{align*}
                transp{A} \
                transp[b]{A}
                end{align*}
                end{document}





                share|improve this answer




























                  3












                  3








                  3







                  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 mathbf{A} dies horribly.



                  documentclass{article}
                  usepackage{amsmath}

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

                  begin{document}
                  begin{align*}
                  transp A \
                  transp{A}
                  end{align*}
                  end{document}


                  A^T//(A)^T



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



                  documentclass{article}
                  usepackage{amsmath}

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

                  begin{document}
                  begin{align*}
                  transp{A} \
                  transp*{A}
                  end{align*}
                  end{document}


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



                  documentclass{article}
                  usepackage{amsmath}

                  makeatletter
                  newcommand{transp}[2][]{%
                  if#1p
                  (#2)
                  else
                  if#1b
                  [A]
                  else
                  A
                  fi
                  fi^{T}
                  }
                  makeatother

                  begin{document}
                  begin{align*}
                  transp{A} \
                  transp[b]{A}
                  end{align*}
                  end{document}





                  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 mathbf{A} dies horribly.



                  documentclass{article}
                  usepackage{amsmath}

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

                  begin{document}
                  begin{align*}
                  transp A \
                  transp{A}
                  end{align*}
                  end{document}


                  A^T//(A)^T



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



                  documentclass{article}
                  usepackage{amsmath}

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

                  begin{document}
                  begin{align*}
                  transp{A} \
                  transp*{A}
                  end{align*}
                  end{document}


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



                  documentclass{article}
                  usepackage{amsmath}

                  makeatletter
                  newcommand{transp}[2][]{%
                  if#1p
                  (#2)
                  else
                  if#1b
                  [A]
                  else
                  A
                  fi
                  fi^{T}
                  }
                  makeatother

                  begin{document}
                  begin{align*}
                  transp{A} \
                  transp[b]{A}
                  end{align*}
                  end{document}






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 1 hour ago

























                  answered 1 hour ago









                  moewemoewe

                  92.2k10115348




                  92.2k10115348






























                      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

                      “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

                      How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

                      夢乃愛華...