How can I define a command that uses round parentheses around its arguments?
Clash Royale CLAN TAG#URR8PPP
up vote
11
down vote
favorite
I defined a command for probability distributions, for example:
usepackageamsmath
usepackagexstring
DeclarePairedDelimiterXRoundBrackets[1]()#1
newcommandp[1]RoundBracketsStrSubstitute[0]#1mid
This can be used as px
. However, I would like to use it as p(x|y)
. Is there some TeX magic to make that possible?
macros parentheses
add a comment |Â
up vote
11
down vote
favorite
I defined a command for probability distributions, for example:
usepackageamsmath
usepackagexstring
DeclarePairedDelimiterXRoundBrackets[1]()#1
newcommandp[1]RoundBracketsStrSubstitute[0]#1mid
This can be used as px
. However, I would like to use it as p(x|y)
. Is there some TeX magic to make that possible?
macros parentheses
Please state your question clearly and give a minimal working example!
â Kuttens
Aug 19 at 15:07
add a comment |Â
up vote
11
down vote
favorite
up vote
11
down vote
favorite
I defined a command for probability distributions, for example:
usepackageamsmath
usepackagexstring
DeclarePairedDelimiterXRoundBrackets[1]()#1
newcommandp[1]RoundBracketsStrSubstitute[0]#1mid
This can be used as px
. However, I would like to use it as p(x|y)
. Is there some TeX magic to make that possible?
macros parentheses
I defined a command for probability distributions, for example:
usepackageamsmath
usepackagexstring
DeclarePairedDelimiterXRoundBrackets[1]()#1
newcommandp[1]RoundBracketsStrSubstitute[0]#1mid
This can be used as px
. However, I would like to use it as p(x|y)
. Is there some TeX magic to make that possible?
macros parentheses
macros parentheses
asked Aug 19 at 15:03
danijar
257212
257212
Please state your question clearly and give a minimal working example!
â Kuttens
Aug 19 at 15:07
add a comment |Â
Please state your question clearly and give a minimal working example!
â Kuttens
Aug 19 at 15:07
Please state your question clearly and give a minimal working example!
â Kuttens
Aug 19 at 15:07
Please state your question clearly and give a minimal working example!
â Kuttens
Aug 19 at 15:07
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
15
down vote
accepted
xparse
makes defining a macro with a different kind of mandatory argument delimiter requirement fairly easy. Below, r()
does just that.
documentclassarticle
usepackagemathtools,xparse,etoolbox
DeclarePairedDelimiterXRoundBrackets[1]()#1
NewDocumentCommandpr r() %
defprArg#1% Capture argument in macro
patchcmdprArgmid% Replace
begindocument
$pr(a|b)$
enddocument
etoolbox
is used to replace |
with mid
.
Great, thank you! This also works with mathematical symbols inside the probability distribution that I had problems with earlier. Is there any reason why defining my probability distributions like this would be discouraged?
â danijar
Aug 19 at 16:11
How would I modify this to pass the symbol in front of the parentheses (p
,q
,p_theta
, etc) into the command? I know I can just write it before the command but it would be easier to see that it belongs together if it were an argument.
â danijar
Aug 19 at 16:22
3
@danijar: Look at this example.
â Werner
Aug 19 at 16:29
add a comment |Â
up vote
11
down vote
This also supports the usual options for DeclarePairedDelimiter
:
documentclassarticle
usepackageamsmath
usepackagexparse
usepackagemleftright
ExplSyntaxOn
NewDocumentCommandpsOr()
IfBooleanTF#1
mleft(
danijar_middlevert:
#3
mright)
group_begin:
danijar_sizedvert:n #2
mathopen#2(
#3
mathclose#2)
group_end:
cs_new_protected:Nn danijar_middlevert:
__danijar_middle:
mathcode`
cs_new_protected:Nn __danijar_middle:
;middlevert;
cs_new_protected:Nn danijar_sizedvert:n
__danijar_mid:
mathcode`
cs_new_protected:Nn __danijar_mid:
mathrell__danijar_size_tlvert
ExplSyntaxOff
begindocument
$p(x) neq p(x|y)$
qquad
$p[big](x) neq p[big](x|y)$
qquad
$p[Big](x) neq p[Big](x|y)$
qquad
$p*(dfracab)neq p*(dfracab|y)$
enddocument
The idea is to locally make |
math active, with an appropriate definition, which is ;middlevert;
when automatic sizing is declared, or mathrel<size>vert
when a manual size is selected.
If you want to add the âÂÂPâ for âÂÂprobabilityâÂÂ:
documentclassarticle
usepackageamsmath
usepackagexparse
usepackagemleftright
ExplSyntaxOn
NewDocumentCommandpsOr()
operatornameP
IfBooleanTF#1
mleft(
danijar_middlevert:
#3
mright)
group_begin:
danijar_sizedvert:n #2
mathopen#2(
#3
mathclose#2)
group_end:
cs_new_protected:Nn danijar_middlevert:
__danijar_middle:
mathcode`
cs_new_protected:Nn __danijar_middle:
;middlevert;
cs_new_protected:Nn danijar_sizedvert:n
__danijar_mid:
mathcode`
cs_new_protected:Nn __danijar_mid:
mathrell__danijar_size_tlvert
ExplSyntaxOff
begindocument
$p(x) neq p(x|y)$
$p[big](x) neq p[big](x|y)$
$p[Big](x) neq p[Big](x|y)$
$p*(dfracab)neq p*(dfracab|y)$
enddocument
Wow, that's amazing. It's a bit more than what I need right now, but if I need symbols of vastly different height inside the parentheses I can go back here and replace the macro with this one.
â danijar
Aug 19 at 16:24
add a comment |Â
up vote
9
down vote
Probably @Werner's answer is the way to go (robust and easily modified), but in this case, plain TeX also seems to work:
documentclassarticle
defpr(#1|#2)(#1 mid #2)
begindocument
$pr(a|b)$
$pr(a_r|b^2)$
enddocument
2
This makes the use of|
also mandatory (for conditional probability), which might not be the case in general. You'll have to update the definition ofpr
to accommodate for that conditional use.
â Werner
Aug 19 at 15:40
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
15
down vote
accepted
xparse
makes defining a macro with a different kind of mandatory argument delimiter requirement fairly easy. Below, r()
does just that.
documentclassarticle
usepackagemathtools,xparse,etoolbox
DeclarePairedDelimiterXRoundBrackets[1]()#1
NewDocumentCommandpr r() %
defprArg#1% Capture argument in macro
patchcmdprArgmid% Replace
begindocument
$pr(a|b)$
enddocument
etoolbox
is used to replace |
with mid
.
Great, thank you! This also works with mathematical symbols inside the probability distribution that I had problems with earlier. Is there any reason why defining my probability distributions like this would be discouraged?
â danijar
Aug 19 at 16:11
How would I modify this to pass the symbol in front of the parentheses (p
,q
,p_theta
, etc) into the command? I know I can just write it before the command but it would be easier to see that it belongs together if it were an argument.
â danijar
Aug 19 at 16:22
3
@danijar: Look at this example.
â Werner
Aug 19 at 16:29
add a comment |Â
up vote
15
down vote
accepted
xparse
makes defining a macro with a different kind of mandatory argument delimiter requirement fairly easy. Below, r()
does just that.
documentclassarticle
usepackagemathtools,xparse,etoolbox
DeclarePairedDelimiterXRoundBrackets[1]()#1
NewDocumentCommandpr r() %
defprArg#1% Capture argument in macro
patchcmdprArgmid% Replace
begindocument
$pr(a|b)$
enddocument
etoolbox
is used to replace |
with mid
.
Great, thank you! This also works with mathematical symbols inside the probability distribution that I had problems with earlier. Is there any reason why defining my probability distributions like this would be discouraged?
â danijar
Aug 19 at 16:11
How would I modify this to pass the symbol in front of the parentheses (p
,q
,p_theta
, etc) into the command? I know I can just write it before the command but it would be easier to see that it belongs together if it were an argument.
â danijar
Aug 19 at 16:22
3
@danijar: Look at this example.
â Werner
Aug 19 at 16:29
add a comment |Â
up vote
15
down vote
accepted
up vote
15
down vote
accepted
xparse
makes defining a macro with a different kind of mandatory argument delimiter requirement fairly easy. Below, r()
does just that.
documentclassarticle
usepackagemathtools,xparse,etoolbox
DeclarePairedDelimiterXRoundBrackets[1]()#1
NewDocumentCommandpr r() %
defprArg#1% Capture argument in macro
patchcmdprArgmid% Replace
begindocument
$pr(a|b)$
enddocument
etoolbox
is used to replace |
with mid
.
xparse
makes defining a macro with a different kind of mandatory argument delimiter requirement fairly easy. Below, r()
does just that.
documentclassarticle
usepackagemathtools,xparse,etoolbox
DeclarePairedDelimiterXRoundBrackets[1]()#1
NewDocumentCommandpr r() %
defprArg#1% Capture argument in macro
patchcmdprArgmid% Replace
begindocument
$pr(a|b)$
enddocument
etoolbox
is used to replace |
with mid
.
answered Aug 19 at 15:16
Werner
421k589171588
421k589171588
Great, thank you! This also works with mathematical symbols inside the probability distribution that I had problems with earlier. Is there any reason why defining my probability distributions like this would be discouraged?
â danijar
Aug 19 at 16:11
How would I modify this to pass the symbol in front of the parentheses (p
,q
,p_theta
, etc) into the command? I know I can just write it before the command but it would be easier to see that it belongs together if it were an argument.
â danijar
Aug 19 at 16:22
3
@danijar: Look at this example.
â Werner
Aug 19 at 16:29
add a comment |Â
Great, thank you! This also works with mathematical symbols inside the probability distribution that I had problems with earlier. Is there any reason why defining my probability distributions like this would be discouraged?
â danijar
Aug 19 at 16:11
How would I modify this to pass the symbol in front of the parentheses (p
,q
,p_theta
, etc) into the command? I know I can just write it before the command but it would be easier to see that it belongs together if it were an argument.
â danijar
Aug 19 at 16:22
3
@danijar: Look at this example.
â Werner
Aug 19 at 16:29
Great, thank you! This also works with mathematical symbols inside the probability distribution that I had problems with earlier. Is there any reason why defining my probability distributions like this would be discouraged?
â danijar
Aug 19 at 16:11
Great, thank you! This also works with mathematical symbols inside the probability distribution that I had problems with earlier. Is there any reason why defining my probability distributions like this would be discouraged?
â danijar
Aug 19 at 16:11
How would I modify this to pass the symbol in front of the parentheses (
p
, q
, p_theta
, etc) into the command? I know I can just write it before the command but it would be easier to see that it belongs together if it were an argument.â danijar
Aug 19 at 16:22
How would I modify this to pass the symbol in front of the parentheses (
p
, q
, p_theta
, etc) into the command? I know I can just write it before the command but it would be easier to see that it belongs together if it were an argument.â danijar
Aug 19 at 16:22
3
3
@danijar: Look at this example.
â Werner
Aug 19 at 16:29
@danijar: Look at this example.
â Werner
Aug 19 at 16:29
add a comment |Â
up vote
11
down vote
This also supports the usual options for DeclarePairedDelimiter
:
documentclassarticle
usepackageamsmath
usepackagexparse
usepackagemleftright
ExplSyntaxOn
NewDocumentCommandpsOr()
IfBooleanTF#1
mleft(
danijar_middlevert:
#3
mright)
group_begin:
danijar_sizedvert:n #2
mathopen#2(
#3
mathclose#2)
group_end:
cs_new_protected:Nn danijar_middlevert:
__danijar_middle:
mathcode`
cs_new_protected:Nn __danijar_middle:
;middlevert;
cs_new_protected:Nn danijar_sizedvert:n
__danijar_mid:
mathcode`
cs_new_protected:Nn __danijar_mid:
mathrell__danijar_size_tlvert
ExplSyntaxOff
begindocument
$p(x) neq p(x|y)$
qquad
$p[big](x) neq p[big](x|y)$
qquad
$p[Big](x) neq p[Big](x|y)$
qquad
$p*(dfracab)neq p*(dfracab|y)$
enddocument
The idea is to locally make |
math active, with an appropriate definition, which is ;middlevert;
when automatic sizing is declared, or mathrel<size>vert
when a manual size is selected.
If you want to add the âÂÂPâ for âÂÂprobabilityâÂÂ:
documentclassarticle
usepackageamsmath
usepackagexparse
usepackagemleftright
ExplSyntaxOn
NewDocumentCommandpsOr()
operatornameP
IfBooleanTF#1
mleft(
danijar_middlevert:
#3
mright)
group_begin:
danijar_sizedvert:n #2
mathopen#2(
#3
mathclose#2)
group_end:
cs_new_protected:Nn danijar_middlevert:
__danijar_middle:
mathcode`
cs_new_protected:Nn __danijar_middle:
;middlevert;
cs_new_protected:Nn danijar_sizedvert:n
__danijar_mid:
mathcode`
cs_new_protected:Nn __danijar_mid:
mathrell__danijar_size_tlvert
ExplSyntaxOff
begindocument
$p(x) neq p(x|y)$
$p[big](x) neq p[big](x|y)$
$p[Big](x) neq p[Big](x|y)$
$p*(dfracab)neq p*(dfracab|y)$
enddocument
Wow, that's amazing. It's a bit more than what I need right now, but if I need symbols of vastly different height inside the parentheses I can go back here and replace the macro with this one.
â danijar
Aug 19 at 16:24
add a comment |Â
up vote
11
down vote
This also supports the usual options for DeclarePairedDelimiter
:
documentclassarticle
usepackageamsmath
usepackagexparse
usepackagemleftright
ExplSyntaxOn
NewDocumentCommandpsOr()
IfBooleanTF#1
mleft(
danijar_middlevert:
#3
mright)
group_begin:
danijar_sizedvert:n #2
mathopen#2(
#3
mathclose#2)
group_end:
cs_new_protected:Nn danijar_middlevert:
__danijar_middle:
mathcode`
cs_new_protected:Nn __danijar_middle:
;middlevert;
cs_new_protected:Nn danijar_sizedvert:n
__danijar_mid:
mathcode`
cs_new_protected:Nn __danijar_mid:
mathrell__danijar_size_tlvert
ExplSyntaxOff
begindocument
$p(x) neq p(x|y)$
qquad
$p[big](x) neq p[big](x|y)$
qquad
$p[Big](x) neq p[Big](x|y)$
qquad
$p*(dfracab)neq p*(dfracab|y)$
enddocument
The idea is to locally make |
math active, with an appropriate definition, which is ;middlevert;
when automatic sizing is declared, or mathrel<size>vert
when a manual size is selected.
If you want to add the âÂÂPâ for âÂÂprobabilityâÂÂ:
documentclassarticle
usepackageamsmath
usepackagexparse
usepackagemleftright
ExplSyntaxOn
NewDocumentCommandpsOr()
operatornameP
IfBooleanTF#1
mleft(
danijar_middlevert:
#3
mright)
group_begin:
danijar_sizedvert:n #2
mathopen#2(
#3
mathclose#2)
group_end:
cs_new_protected:Nn danijar_middlevert:
__danijar_middle:
mathcode`
cs_new_protected:Nn __danijar_middle:
;middlevert;
cs_new_protected:Nn danijar_sizedvert:n
__danijar_mid:
mathcode`
cs_new_protected:Nn __danijar_mid:
mathrell__danijar_size_tlvert
ExplSyntaxOff
begindocument
$p(x) neq p(x|y)$
$p[big](x) neq p[big](x|y)$
$p[Big](x) neq p[Big](x|y)$
$p*(dfracab)neq p*(dfracab|y)$
enddocument
Wow, that's amazing. It's a bit more than what I need right now, but if I need symbols of vastly different height inside the parentheses I can go back here and replace the macro with this one.
â danijar
Aug 19 at 16:24
add a comment |Â
up vote
11
down vote
up vote
11
down vote
This also supports the usual options for DeclarePairedDelimiter
:
documentclassarticle
usepackageamsmath
usepackagexparse
usepackagemleftright
ExplSyntaxOn
NewDocumentCommandpsOr()
IfBooleanTF#1
mleft(
danijar_middlevert:
#3
mright)
group_begin:
danijar_sizedvert:n #2
mathopen#2(
#3
mathclose#2)
group_end:
cs_new_protected:Nn danijar_middlevert:
__danijar_middle:
mathcode`
cs_new_protected:Nn __danijar_middle:
;middlevert;
cs_new_protected:Nn danijar_sizedvert:n
__danijar_mid:
mathcode`
cs_new_protected:Nn __danijar_mid:
mathrell__danijar_size_tlvert
ExplSyntaxOff
begindocument
$p(x) neq p(x|y)$
qquad
$p[big](x) neq p[big](x|y)$
qquad
$p[Big](x) neq p[Big](x|y)$
qquad
$p*(dfracab)neq p*(dfracab|y)$
enddocument
The idea is to locally make |
math active, with an appropriate definition, which is ;middlevert;
when automatic sizing is declared, or mathrel<size>vert
when a manual size is selected.
If you want to add the âÂÂPâ for âÂÂprobabilityâÂÂ:
documentclassarticle
usepackageamsmath
usepackagexparse
usepackagemleftright
ExplSyntaxOn
NewDocumentCommandpsOr()
operatornameP
IfBooleanTF#1
mleft(
danijar_middlevert:
#3
mright)
group_begin:
danijar_sizedvert:n #2
mathopen#2(
#3
mathclose#2)
group_end:
cs_new_protected:Nn danijar_middlevert:
__danijar_middle:
mathcode`
cs_new_protected:Nn __danijar_middle:
;middlevert;
cs_new_protected:Nn danijar_sizedvert:n
__danijar_mid:
mathcode`
cs_new_protected:Nn __danijar_mid:
mathrell__danijar_size_tlvert
ExplSyntaxOff
begindocument
$p(x) neq p(x|y)$
$p[big](x) neq p[big](x|y)$
$p[Big](x) neq p[Big](x|y)$
$p*(dfracab)neq p*(dfracab|y)$
enddocument
This also supports the usual options for DeclarePairedDelimiter
:
documentclassarticle
usepackageamsmath
usepackagexparse
usepackagemleftright
ExplSyntaxOn
NewDocumentCommandpsOr()
IfBooleanTF#1
mleft(
danijar_middlevert:
#3
mright)
group_begin:
danijar_sizedvert:n #2
mathopen#2(
#3
mathclose#2)
group_end:
cs_new_protected:Nn danijar_middlevert:
__danijar_middle:
mathcode`
cs_new_protected:Nn __danijar_middle:
;middlevert;
cs_new_protected:Nn danijar_sizedvert:n
__danijar_mid:
mathcode`
cs_new_protected:Nn __danijar_mid:
mathrell__danijar_size_tlvert
ExplSyntaxOff
begindocument
$p(x) neq p(x|y)$
qquad
$p[big](x) neq p[big](x|y)$
qquad
$p[Big](x) neq p[Big](x|y)$
qquad
$p*(dfracab)neq p*(dfracab|y)$
enddocument
The idea is to locally make |
math active, with an appropriate definition, which is ;middlevert;
when automatic sizing is declared, or mathrel<size>vert
when a manual size is selected.
If you want to add the âÂÂPâ for âÂÂprobabilityâÂÂ:
documentclassarticle
usepackageamsmath
usepackagexparse
usepackagemleftright
ExplSyntaxOn
NewDocumentCommandpsOr()
operatornameP
IfBooleanTF#1
mleft(
danijar_middlevert:
#3
mright)
group_begin:
danijar_sizedvert:n #2
mathopen#2(
#3
mathclose#2)
group_end:
cs_new_protected:Nn danijar_middlevert:
__danijar_middle:
mathcode`
cs_new_protected:Nn __danijar_middle:
;middlevert;
cs_new_protected:Nn danijar_sizedvert:n
__danijar_mid:
mathcode`
cs_new_protected:Nn __danijar_mid:
mathrell__danijar_size_tlvert
ExplSyntaxOff
begindocument
$p(x) neq p(x|y)$
$p[big](x) neq p[big](x|y)$
$p[Big](x) neq p[Big](x|y)$
$p*(dfracab)neq p*(dfracab|y)$
enddocument
edited Aug 19 at 16:17
answered Aug 19 at 16:12
egreg
683k8418203066
683k8418203066
Wow, that's amazing. It's a bit more than what I need right now, but if I need symbols of vastly different height inside the parentheses I can go back here and replace the macro with this one.
â danijar
Aug 19 at 16:24
add a comment |Â
Wow, that's amazing. It's a bit more than what I need right now, but if I need symbols of vastly different height inside the parentheses I can go back here and replace the macro with this one.
â danijar
Aug 19 at 16:24
Wow, that's amazing. It's a bit more than what I need right now, but if I need symbols of vastly different height inside the parentheses I can go back here and replace the macro with this one.
â danijar
Aug 19 at 16:24
Wow, that's amazing. It's a bit more than what I need right now, but if I need symbols of vastly different height inside the parentheses I can go back here and replace the macro with this one.
â danijar
Aug 19 at 16:24
add a comment |Â
up vote
9
down vote
Probably @Werner's answer is the way to go (robust and easily modified), but in this case, plain TeX also seems to work:
documentclassarticle
defpr(#1|#2)(#1 mid #2)
begindocument
$pr(a|b)$
$pr(a_r|b^2)$
enddocument
2
This makes the use of|
also mandatory (for conditional probability), which might not be the case in general. You'll have to update the definition ofpr
to accommodate for that conditional use.
â Werner
Aug 19 at 15:40
add a comment |Â
up vote
9
down vote
Probably @Werner's answer is the way to go (robust and easily modified), but in this case, plain TeX also seems to work:
documentclassarticle
defpr(#1|#2)(#1 mid #2)
begindocument
$pr(a|b)$
$pr(a_r|b^2)$
enddocument
2
This makes the use of|
also mandatory (for conditional probability), which might not be the case in general. You'll have to update the definition ofpr
to accommodate for that conditional use.
â Werner
Aug 19 at 15:40
add a comment |Â
up vote
9
down vote
up vote
9
down vote
Probably @Werner's answer is the way to go (robust and easily modified), but in this case, plain TeX also seems to work:
documentclassarticle
defpr(#1|#2)(#1 mid #2)
begindocument
$pr(a|b)$
$pr(a_r|b^2)$
enddocument
Probably @Werner's answer is the way to go (robust and easily modified), but in this case, plain TeX also seems to work:
documentclassarticle
defpr(#1|#2)(#1 mid #2)
begindocument
$pr(a|b)$
$pr(a_r|b^2)$
enddocument
answered Aug 19 at 15:33
Rmano
6,97121446
6,97121446
2
This makes the use of|
also mandatory (for conditional probability), which might not be the case in general. You'll have to update the definition ofpr
to accommodate for that conditional use.
â Werner
Aug 19 at 15:40
add a comment |Â
2
This makes the use of|
also mandatory (for conditional probability), which might not be the case in general. You'll have to update the definition ofpr
to accommodate for that conditional use.
â Werner
Aug 19 at 15:40
2
2
This makes the use of
|
also mandatory (for conditional probability), which might not be the case in general. You'll have to update the definition of pr
to accommodate for that conditional use.â Werner
Aug 19 at 15:40
This makes the use of
|
also mandatory (for conditional probability), which might not be the case in general. You'll have to update the definition of pr
to accommodate for that conditional use.â Werner
Aug 19 at 15:40
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f446677%2fhow-can-i-define-a-command-that-uses-round-parentheses-around-its-arguments%23new-answer', 'question_page');
);
Post as a guest
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
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
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
Please state your question clearly and give a minimal working example!
â Kuttens
Aug 19 at 15:07