Transpose a matrix and parenthesis

Clash Royale CLAN TAG#URR8PPP
I would like to define a command transp having eventually one argument : the name of the matrix and finally two outputs.
transpAis the matrix A^T between parenthesis,transp Ais 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
add a comment |
I would like to define a command transp having eventually one argument : the name of the matrix and finally two outputs.
transpAis the matrix A^T between parenthesis,transp Ais 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
2
Usuallyfoo AandfooAare the same for a macrofootaking 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
add a comment |
I would like to define a command transp having eventually one argument : the name of the matrix and finally two outputs.
transpAis the matrix A^T between parenthesis,transp Ais 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
I would like to define a command transp having eventually one argument : the name of the matrix and finally two outputs.
transpAis the matrix A^T between parenthesis,transp Ais 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
macros conditionals math-operators
asked Feb 28 at 11:33
jowe_19jowe_19
7510
7510
2
Usuallyfoo AandfooAare the same for a macrofootaking 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
add a comment |
2
Usuallyfoo AandfooAare the same for a macrofootaking 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
add a comment |
2 Answers
2
active
oldest
votes
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.

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
add a comment |
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 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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.

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
add a comment |
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.

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
add a comment |
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.

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

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
answered Feb 28 at 11:44
egregegreg
729k8819273240
729k8819273240
add a comment |
add a comment |
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 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
add a comment |
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 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
add a comment |
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 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
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 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
edited Feb 28 at 11:54
answered Feb 28 at 11:44
moewemoewe
95.1k10115358
95.1k10115358
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
2
Usually
foo AandfooAare the same for a macrofootaking 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