Problems with def
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have created the following macros in LaTeX:
deftwomate(#1,#2,#3,#4)beginpmatrix#1\#3endpmatrix
defpwr(#1)^#1
deftwoclmn(#1,#2)beginpmatrix#1\#2endpmatrix
Where twomate
is a 2x2 matrix, twoclmn
creates a 2x1 column vector, and pwr
is a command to raise the argument to the power.
However, if I try to do the following:
$$twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t) )$$
I get an error. However, if I replace the last entry with something that is not a def
command:
$$twomate(3epwr(-3t),epwr(2t),-epwr(-3t),5 )$$
The document complies successfully. In addition, the following does not compile successfully:
$$twoclmn(frac625epwr(2t)-frac15tepwr(2t),-frac225epwr(2t) + frac25 t epwr(2t))$$
But the following does:
$$twoclmn(frac625e^2t-frac15te^2t,-frac225e^2t + frac25 t e^2t)$$
So the problem seems to be the nested def
commands. How may I nest def
commands, without the compiler complaining?
math-mode macros
New contributor
add a comment |
up vote
1
down vote
favorite
I have created the following macros in LaTeX:
deftwomate(#1,#2,#3,#4)beginpmatrix#1\#3endpmatrix
defpwr(#1)^#1
deftwoclmn(#1,#2)beginpmatrix#1\#2endpmatrix
Where twomate
is a 2x2 matrix, twoclmn
creates a 2x1 column vector, and pwr
is a command to raise the argument to the power.
However, if I try to do the following:
$$twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t) )$$
I get an error. However, if I replace the last entry with something that is not a def
command:
$$twomate(3epwr(-3t),epwr(2t),-epwr(-3t),5 )$$
The document complies successfully. In addition, the following does not compile successfully:
$$twoclmn(frac625epwr(2t)-frac15tepwr(2t),-frac225epwr(2t) + frac25 t epwr(2t))$$
But the following does:
$$twoclmn(frac625e^2t-frac15te^2t,-frac225e^2t + frac25 t e^2t)$$
So the problem seems to be the nested def
commands. How may I nest def
commands, without the compiler complaining?
math-mode macros
New contributor
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have created the following macros in LaTeX:
deftwomate(#1,#2,#3,#4)beginpmatrix#1\#3endpmatrix
defpwr(#1)^#1
deftwoclmn(#1,#2)beginpmatrix#1\#2endpmatrix
Where twomate
is a 2x2 matrix, twoclmn
creates a 2x1 column vector, and pwr
is a command to raise the argument to the power.
However, if I try to do the following:
$$twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t) )$$
I get an error. However, if I replace the last entry with something that is not a def
command:
$$twomate(3epwr(-3t),epwr(2t),-epwr(-3t),5 )$$
The document complies successfully. In addition, the following does not compile successfully:
$$twoclmn(frac625epwr(2t)-frac15tepwr(2t),-frac225epwr(2t) + frac25 t epwr(2t))$$
But the following does:
$$twoclmn(frac625e^2t-frac15te^2t,-frac225e^2t + frac25 t e^2t)$$
So the problem seems to be the nested def
commands. How may I nest def
commands, without the compiler complaining?
math-mode macros
New contributor
I have created the following macros in LaTeX:
deftwomate(#1,#2,#3,#4)beginpmatrix#1\#3endpmatrix
defpwr(#1)^#1
deftwoclmn(#1,#2)beginpmatrix#1\#2endpmatrix
Where twomate
is a 2x2 matrix, twoclmn
creates a 2x1 column vector, and pwr
is a command to raise the argument to the power.
However, if I try to do the following:
$$twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t) )$$
I get an error. However, if I replace the last entry with something that is not a def
command:
$$twomate(3epwr(-3t),epwr(2t),-epwr(-3t),5 )$$
The document complies successfully. In addition, the following does not compile successfully:
$$twoclmn(frac625epwr(2t)-frac15tepwr(2t),-frac225epwr(2t) + frac25 t epwr(2t))$$
But the following does:
$$twoclmn(frac625e^2t-frac15te^2t,-frac225e^2t + frac25 t e^2t)$$
So the problem seems to be the nested def
commands. How may I nest def
commands, without the compiler complaining?
math-mode macros
math-mode macros
New contributor
New contributor
New contributor
asked 4 hours ago
Hossmeister
61
61
New contributor
New contributor
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
2
down vote
TeX's delimited parameters parsing doesn't take nesting into account properly. So if you call twomate(3epwr(-3t), ...)
, the final )
for twomate
isn't found at the end of that line but at the end of pwr(-3t)
. The improperly formed call of pwr
then causes trouble.
To hide nested calls of your commands, put them into ...
groups (though this probably defeats the purpose):
documentclassarticle
usepackageamsmath
deftwomate(#1,#2,#3,#4)beginpmatrix#1\#3endpmatrix
defpwr(#1)^#1
deftwoclmn(#1,#2)beginpmatrix#1\#2endpmatrix
begindocument
[ twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t)) ]
enddocument
By the way, don't use $$ ... $$
for display math environments but LaTeX's or amsmath
's variants like [ ... ]
.
add a comment |
up vote
2
down vote
You can use xparse
for this job, because the r
argument type takes care of nesting.
documentclassarticle
usepackageamsmath
usepackagexparse
NewDocumentCommandtwomate>SplitArgument3,r()%
maketwomate#1%
NewDocumentCommandmaketwomatemmmm%
beginpmatrix#1\#3endpmatrix%
NewDocumentCommandpwrr()^#1
begindocument
[
twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t) )
]
enddocument
However, using ()
as delimiters doesn't seem a good idea. The following is as clear and behaves better with syntax coloring of front ends.
documentclassarticle
usepackageamsmath
usepackagexparse
NewDocumentCommandtwomate>SplitArgument3,m%
maketwomate#1%
NewDocumentCommandmaketwomatemmmm%
beginpmatrix#1\#3endpmatrix%
NewDocumentCommandpwrm^#1
begindocument
[
twomate3epwr-3t,epwr2t,-epwr-3t,-2epwr2t
]
enddocument
add a comment |
up vote
1
down vote
Your def
contains a very specific sequence defined as the parameter text:
% 1 2 3 4 5
deftwomate(<1>,<2>,<3>,<4>) ...
% ^ ^ ^ ^ ^
% │ │ │ │ │
% │ └ comma ┘ │
% └─── bracket ───┘
This parameter text is matched exactly in order (almost like a first-come-first-served style) to extract the four arguments <1>
, <2>
, <3>
and <4>
. Here's how the elements are grabbed for twomate
with the above notation:
% 1 2 3 4 5
twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
% ^ ^ ^ ^ ^
% │ │ │ │ │
% │ └────── comma ────────┘ │
% └───────────────── bracket ──────────────────┘
It should be clear that the last bracket )
isn't properly captured for pwr
. The way around it is to hide pwr(.)
from twomate
:
documentclassarticle
usepackageamsmath
deftwomate(#1,#2,#3,#4)beginpmatrix#1\#3endpmatrix
defpwr(#1)^#1
begindocument
[
twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
]
enddocument
This solves the problem only temporarily. If you nest elements, you'll run into similar problems because of the parameter text pattern matching. In general, it is safer to group arguments using ...
.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
TeX's delimited parameters parsing doesn't take nesting into account properly. So if you call twomate(3epwr(-3t), ...)
, the final )
for twomate
isn't found at the end of that line but at the end of pwr(-3t)
. The improperly formed call of pwr
then causes trouble.
To hide nested calls of your commands, put them into ...
groups (though this probably defeats the purpose):
documentclassarticle
usepackageamsmath
deftwomate(#1,#2,#3,#4)beginpmatrix#1\#3endpmatrix
defpwr(#1)^#1
deftwoclmn(#1,#2)beginpmatrix#1\#2endpmatrix
begindocument
[ twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t)) ]
enddocument
By the way, don't use $$ ... $$
for display math environments but LaTeX's or amsmath
's variants like [ ... ]
.
add a comment |
up vote
2
down vote
TeX's delimited parameters parsing doesn't take nesting into account properly. So if you call twomate(3epwr(-3t), ...)
, the final )
for twomate
isn't found at the end of that line but at the end of pwr(-3t)
. The improperly formed call of pwr
then causes trouble.
To hide nested calls of your commands, put them into ...
groups (though this probably defeats the purpose):
documentclassarticle
usepackageamsmath
deftwomate(#1,#2,#3,#4)beginpmatrix#1\#3endpmatrix
defpwr(#1)^#1
deftwoclmn(#1,#2)beginpmatrix#1\#2endpmatrix
begindocument
[ twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t)) ]
enddocument
By the way, don't use $$ ... $$
for display math environments but LaTeX's or amsmath
's variants like [ ... ]
.
add a comment |
up vote
2
down vote
up vote
2
down vote
TeX's delimited parameters parsing doesn't take nesting into account properly. So if you call twomate(3epwr(-3t), ...)
, the final )
for twomate
isn't found at the end of that line but at the end of pwr(-3t)
. The improperly formed call of pwr
then causes trouble.
To hide nested calls of your commands, put them into ...
groups (though this probably defeats the purpose):
documentclassarticle
usepackageamsmath
deftwomate(#1,#2,#3,#4)beginpmatrix#1\#3endpmatrix
defpwr(#1)^#1
deftwoclmn(#1,#2)beginpmatrix#1\#2endpmatrix
begindocument
[ twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t)) ]
enddocument
By the way, don't use $$ ... $$
for display math environments but LaTeX's or amsmath
's variants like [ ... ]
.
TeX's delimited parameters parsing doesn't take nesting into account properly. So if you call twomate(3epwr(-3t), ...)
, the final )
for twomate
isn't found at the end of that line but at the end of pwr(-3t)
. The improperly formed call of pwr
then causes trouble.
To hide nested calls of your commands, put them into ...
groups (though this probably defeats the purpose):
documentclassarticle
usepackageamsmath
deftwomate(#1,#2,#3,#4)beginpmatrix#1\#3endpmatrix
defpwr(#1)^#1
deftwoclmn(#1,#2)beginpmatrix#1\#2endpmatrix
begindocument
[ twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t)) ]
enddocument
By the way, don't use $$ ... $$
for display math environments but LaTeX's or amsmath
's variants like [ ... ]
.
edited 3 hours ago
answered 3 hours ago
siracusa
4,26911127
4,26911127
add a comment |
add a comment |
up vote
2
down vote
You can use xparse
for this job, because the r
argument type takes care of nesting.
documentclassarticle
usepackageamsmath
usepackagexparse
NewDocumentCommandtwomate>SplitArgument3,r()%
maketwomate#1%
NewDocumentCommandmaketwomatemmmm%
beginpmatrix#1\#3endpmatrix%
NewDocumentCommandpwrr()^#1
begindocument
[
twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t) )
]
enddocument
However, using ()
as delimiters doesn't seem a good idea. The following is as clear and behaves better with syntax coloring of front ends.
documentclassarticle
usepackageamsmath
usepackagexparse
NewDocumentCommandtwomate>SplitArgument3,m%
maketwomate#1%
NewDocumentCommandmaketwomatemmmm%
beginpmatrix#1\#3endpmatrix%
NewDocumentCommandpwrm^#1
begindocument
[
twomate3epwr-3t,epwr2t,-epwr-3t,-2epwr2t
]
enddocument
add a comment |
up vote
2
down vote
You can use xparse
for this job, because the r
argument type takes care of nesting.
documentclassarticle
usepackageamsmath
usepackagexparse
NewDocumentCommandtwomate>SplitArgument3,r()%
maketwomate#1%
NewDocumentCommandmaketwomatemmmm%
beginpmatrix#1\#3endpmatrix%
NewDocumentCommandpwrr()^#1
begindocument
[
twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t) )
]
enddocument
However, using ()
as delimiters doesn't seem a good idea. The following is as clear and behaves better with syntax coloring of front ends.
documentclassarticle
usepackageamsmath
usepackagexparse
NewDocumentCommandtwomate>SplitArgument3,m%
maketwomate#1%
NewDocumentCommandmaketwomatemmmm%
beginpmatrix#1\#3endpmatrix%
NewDocumentCommandpwrm^#1
begindocument
[
twomate3epwr-3t,epwr2t,-epwr-3t,-2epwr2t
]
enddocument
add a comment |
up vote
2
down vote
up vote
2
down vote
You can use xparse
for this job, because the r
argument type takes care of nesting.
documentclassarticle
usepackageamsmath
usepackagexparse
NewDocumentCommandtwomate>SplitArgument3,r()%
maketwomate#1%
NewDocumentCommandmaketwomatemmmm%
beginpmatrix#1\#3endpmatrix%
NewDocumentCommandpwrr()^#1
begindocument
[
twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t) )
]
enddocument
However, using ()
as delimiters doesn't seem a good idea. The following is as clear and behaves better with syntax coloring of front ends.
documentclassarticle
usepackageamsmath
usepackagexparse
NewDocumentCommandtwomate>SplitArgument3,m%
maketwomate#1%
NewDocumentCommandmaketwomatemmmm%
beginpmatrix#1\#3endpmatrix%
NewDocumentCommandpwrm^#1
begindocument
[
twomate3epwr-3t,epwr2t,-epwr-3t,-2epwr2t
]
enddocument
You can use xparse
for this job, because the r
argument type takes care of nesting.
documentclassarticle
usepackageamsmath
usepackagexparse
NewDocumentCommandtwomate>SplitArgument3,r()%
maketwomate#1%
NewDocumentCommandmaketwomatemmmm%
beginpmatrix#1\#3endpmatrix%
NewDocumentCommandpwrr()^#1
begindocument
[
twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t) )
]
enddocument
However, using ()
as delimiters doesn't seem a good idea. The following is as clear and behaves better with syntax coloring of front ends.
documentclassarticle
usepackageamsmath
usepackagexparse
NewDocumentCommandtwomate>SplitArgument3,m%
maketwomate#1%
NewDocumentCommandmaketwomatemmmm%
beginpmatrix#1\#3endpmatrix%
NewDocumentCommandpwrm^#1
begindocument
[
twomate3epwr-3t,epwr2t,-epwr-3t,-2epwr2t
]
enddocument
answered 2 hours ago
egreg
696k8518473104
696k8518473104
add a comment |
add a comment |
up vote
1
down vote
Your def
contains a very specific sequence defined as the parameter text:
% 1 2 3 4 5
deftwomate(<1>,<2>,<3>,<4>) ...
% ^ ^ ^ ^ ^
% │ │ │ │ │
% │ └ comma ┘ │
% └─── bracket ───┘
This parameter text is matched exactly in order (almost like a first-come-first-served style) to extract the four arguments <1>
, <2>
, <3>
and <4>
. Here's how the elements are grabbed for twomate
with the above notation:
% 1 2 3 4 5
twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
% ^ ^ ^ ^ ^
% │ │ │ │ │
% │ └────── comma ────────┘ │
% └───────────────── bracket ──────────────────┘
It should be clear that the last bracket )
isn't properly captured for pwr
. The way around it is to hide pwr(.)
from twomate
:
documentclassarticle
usepackageamsmath
deftwomate(#1,#2,#3,#4)beginpmatrix#1\#3endpmatrix
defpwr(#1)^#1
begindocument
[
twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
]
enddocument
This solves the problem only temporarily. If you nest elements, you'll run into similar problems because of the parameter text pattern matching. In general, it is safer to group arguments using ...
.
add a comment |
up vote
1
down vote
Your def
contains a very specific sequence defined as the parameter text:
% 1 2 3 4 5
deftwomate(<1>,<2>,<3>,<4>) ...
% ^ ^ ^ ^ ^
% │ │ │ │ │
% │ └ comma ┘ │
% └─── bracket ───┘
This parameter text is matched exactly in order (almost like a first-come-first-served style) to extract the four arguments <1>
, <2>
, <3>
and <4>
. Here's how the elements are grabbed for twomate
with the above notation:
% 1 2 3 4 5
twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
% ^ ^ ^ ^ ^
% │ │ │ │ │
% │ └────── comma ────────┘ │
% └───────────────── bracket ──────────────────┘
It should be clear that the last bracket )
isn't properly captured for pwr
. The way around it is to hide pwr(.)
from twomate
:
documentclassarticle
usepackageamsmath
deftwomate(#1,#2,#3,#4)beginpmatrix#1\#3endpmatrix
defpwr(#1)^#1
begindocument
[
twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
]
enddocument
This solves the problem only temporarily. If you nest elements, you'll run into similar problems because of the parameter text pattern matching. In general, it is safer to group arguments using ...
.
add a comment |
up vote
1
down vote
up vote
1
down vote
Your def
contains a very specific sequence defined as the parameter text:
% 1 2 3 4 5
deftwomate(<1>,<2>,<3>,<4>) ...
% ^ ^ ^ ^ ^
% │ │ │ │ │
% │ └ comma ┘ │
% └─── bracket ───┘
This parameter text is matched exactly in order (almost like a first-come-first-served style) to extract the four arguments <1>
, <2>
, <3>
and <4>
. Here's how the elements are grabbed for twomate
with the above notation:
% 1 2 3 4 5
twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
% ^ ^ ^ ^ ^
% │ │ │ │ │
% │ └────── comma ────────┘ │
% └───────────────── bracket ──────────────────┘
It should be clear that the last bracket )
isn't properly captured for pwr
. The way around it is to hide pwr(.)
from twomate
:
documentclassarticle
usepackageamsmath
deftwomate(#1,#2,#3,#4)beginpmatrix#1\#3endpmatrix
defpwr(#1)^#1
begindocument
[
twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
]
enddocument
This solves the problem only temporarily. If you nest elements, you'll run into similar problems because of the parameter text pattern matching. In general, it is safer to group arguments using ...
.
Your def
contains a very specific sequence defined as the parameter text:
% 1 2 3 4 5
deftwomate(<1>,<2>,<3>,<4>) ...
% ^ ^ ^ ^ ^
% │ │ │ │ │
% │ └ comma ┘ │
% └─── bracket ───┘
This parameter text is matched exactly in order (almost like a first-come-first-served style) to extract the four arguments <1>
, <2>
, <3>
and <4>
. Here's how the elements are grabbed for twomate
with the above notation:
% 1 2 3 4 5
twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
% ^ ^ ^ ^ ^
% │ │ │ │ │
% │ └────── comma ────────┘ │
% └───────────────── bracket ──────────────────┘
It should be clear that the last bracket )
isn't properly captured for pwr
. The way around it is to hide pwr(.)
from twomate
:
documentclassarticle
usepackageamsmath
deftwomate(#1,#2,#3,#4)beginpmatrix#1\#3endpmatrix
defpwr(#1)^#1
begindocument
[
twomate(3epwr(-3t),epwr(2t),-epwr(-3t),-2epwr(2t))
]
enddocument
This solves the problem only temporarily. If you nest elements, you'll run into similar problems because of the parameter text pattern matching. In general, it is safer to group arguments using ...
.
edited 3 hours ago
answered 3 hours ago
Werner
429k589401618
429k589401618
add a comment |
add a comment |
Hossmeister is a new contributor. Be nice, and check out our Code of Conduct.
Hossmeister is a new contributor. Be nice, and check out our Code of Conduct.
Hossmeister is a new contributor. Be nice, and check out our Code of Conduct.
Hossmeister is a new contributor. Be nice, and check out our Code of Conduct.
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%2f459229%2fproblems-with-def%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