How to use true/false inside definitions?
up vote
4
down vote
favorite
Suppose you want to define page style depending on a boolean value.
I think both constructions below have equivalent output (or not?), but which is better/more indicated/professional/elegant?
if@mybool
defps@myps{
% definition here
}
else
defps@myps{
% definition here
}
fi
or
defps@myps{
if@mybool
% definition here
else
% definition here
fi
}
conditionals sourcecode pagestyle
add a comment |
up vote
4
down vote
favorite
Suppose you want to define page style depending on a boolean value.
I think both constructions below have equivalent output (or not?), but which is better/more indicated/professional/elegant?
if@mybool
defps@myps{
% definition here
}
else
defps@myps{
% definition here
}
fi
or
defps@myps{
if@mybool
% definition here
else
% definition here
fi
}
conditionals sourcecode pagestyle
2
They aren't equivalent. The former testsif@mybool
at definition time, the latter at call time.
– egreg
Nov 8 at 11:40
@egreg, oh, I see. But do you have some reason to choose one? I mean, could I get some bug or problem if I choose wrong?
– Sigur
Nov 8 at 11:42
The two constructs do different things, so generally only one is correct according to what you need to do.
– egreg
Nov 8 at 11:45
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
Suppose you want to define page style depending on a boolean value.
I think both constructions below have equivalent output (or not?), but which is better/more indicated/professional/elegant?
if@mybool
defps@myps{
% definition here
}
else
defps@myps{
% definition here
}
fi
or
defps@myps{
if@mybool
% definition here
else
% definition here
fi
}
conditionals sourcecode pagestyle
Suppose you want to define page style depending on a boolean value.
I think both constructions below have equivalent output (or not?), but which is better/more indicated/professional/elegant?
if@mybool
defps@myps{
% definition here
}
else
defps@myps{
% definition here
}
fi
or
defps@myps{
if@mybool
% definition here
else
% definition here
fi
}
conditionals sourcecode pagestyle
conditionals sourcecode pagestyle
edited Nov 8 at 11:44
asked Nov 8 at 11:38
Sigur
23.1k353134
23.1k353134
2
They aren't equivalent. The former testsif@mybool
at definition time, the latter at call time.
– egreg
Nov 8 at 11:40
@egreg, oh, I see. But do you have some reason to choose one? I mean, could I get some bug or problem if I choose wrong?
– Sigur
Nov 8 at 11:42
The two constructs do different things, so generally only one is correct according to what you need to do.
– egreg
Nov 8 at 11:45
add a comment |
2
They aren't equivalent. The former testsif@mybool
at definition time, the latter at call time.
– egreg
Nov 8 at 11:40
@egreg, oh, I see. But do you have some reason to choose one? I mean, could I get some bug or problem if I choose wrong?
– Sigur
Nov 8 at 11:42
The two constructs do different things, so generally only one is correct according to what you need to do.
– egreg
Nov 8 at 11:45
2
2
They aren't equivalent. The former tests
if@mybool
at definition time, the latter at call time.– egreg
Nov 8 at 11:40
They aren't equivalent. The former tests
if@mybool
at definition time, the latter at call time.– egreg
Nov 8 at 11:40
@egreg, oh, I see. But do you have some reason to choose one? I mean, could I get some bug or problem if I choose wrong?
– Sigur
Nov 8 at 11:42
@egreg, oh, I see. But do you have some reason to choose one? I mean, could I get some bug or problem if I choose wrong?
– Sigur
Nov 8 at 11:42
The two constructs do different things, so generally only one is correct according to what you need to do.
– egreg
Nov 8 at 11:45
The two constructs do different things, so generally only one is correct according to what you need to do.
– egreg
Nov 8 at 11:45
add a comment |
1 Answer
1
active
oldest
votes
up vote
7
down vote
accepted
The two constructs aren't equivalent.
With
if@mybool
defps@myps{...T...}%
else
defps@myps{...F...}%
fi
you test if@mybool
and define ps@myps
according to its truth value. Changing the value later in the document will not change the definition of ps@myps
.
To the contrary,
defps@myps{%
if@mybool
...A...%
else
...B...%
fi
}
will yield ...A...
or ...B...
according the the truth value of if@mybool
at the time the macro is expanded.
Which one to use depends on what you need to achieve.
With the first definition, if issued when if@mybool
is true,
@myboolfalse
ps@myps
@myboolfalse
ps@myps
will produce ...A...
twice.
With the second definition, the above code would produce first ...B...
and then ...A...
.
If you are writing a package and if@mybool
is set by a package options at runtime, most likely you want to use the first model, as the macro name suggests you're trying to define a page style that probably shouldn't change mid document.
The situation is quite similar to let
and def
. With letmymacroanother
you define mymacro
to be the same another
is at the time the let
instruction is performed.
With defmymacro{another}
, the meaning of another
current at the moment mymacro
is called will be used, which can have changed in the meantime.
1
Changing the value later in the document will not change the definition ofps@myps
explained a lot to me. Very nice!
– Sigur
Nov 8 at 11:46
@Sigur I added some more comments
– egreg
Nov 8 at 11:50
I got it. That is the point,mybool
will not change, because it comes from an option within the class. Thanks.
– Sigur
Nov 8 at 11:57
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
accepted
The two constructs aren't equivalent.
With
if@mybool
defps@myps{...T...}%
else
defps@myps{...F...}%
fi
you test if@mybool
and define ps@myps
according to its truth value. Changing the value later in the document will not change the definition of ps@myps
.
To the contrary,
defps@myps{%
if@mybool
...A...%
else
...B...%
fi
}
will yield ...A...
or ...B...
according the the truth value of if@mybool
at the time the macro is expanded.
Which one to use depends on what you need to achieve.
With the first definition, if issued when if@mybool
is true,
@myboolfalse
ps@myps
@myboolfalse
ps@myps
will produce ...A...
twice.
With the second definition, the above code would produce first ...B...
and then ...A...
.
If you are writing a package and if@mybool
is set by a package options at runtime, most likely you want to use the first model, as the macro name suggests you're trying to define a page style that probably shouldn't change mid document.
The situation is quite similar to let
and def
. With letmymacroanother
you define mymacro
to be the same another
is at the time the let
instruction is performed.
With defmymacro{another}
, the meaning of another
current at the moment mymacro
is called will be used, which can have changed in the meantime.
1
Changing the value later in the document will not change the definition ofps@myps
explained a lot to me. Very nice!
– Sigur
Nov 8 at 11:46
@Sigur I added some more comments
– egreg
Nov 8 at 11:50
I got it. That is the point,mybool
will not change, because it comes from an option within the class. Thanks.
– Sigur
Nov 8 at 11:57
add a comment |
up vote
7
down vote
accepted
The two constructs aren't equivalent.
With
if@mybool
defps@myps{...T...}%
else
defps@myps{...F...}%
fi
you test if@mybool
and define ps@myps
according to its truth value. Changing the value later in the document will not change the definition of ps@myps
.
To the contrary,
defps@myps{%
if@mybool
...A...%
else
...B...%
fi
}
will yield ...A...
or ...B...
according the the truth value of if@mybool
at the time the macro is expanded.
Which one to use depends on what you need to achieve.
With the first definition, if issued when if@mybool
is true,
@myboolfalse
ps@myps
@myboolfalse
ps@myps
will produce ...A...
twice.
With the second definition, the above code would produce first ...B...
and then ...A...
.
If you are writing a package and if@mybool
is set by a package options at runtime, most likely you want to use the first model, as the macro name suggests you're trying to define a page style that probably shouldn't change mid document.
The situation is quite similar to let
and def
. With letmymacroanother
you define mymacro
to be the same another
is at the time the let
instruction is performed.
With defmymacro{another}
, the meaning of another
current at the moment mymacro
is called will be used, which can have changed in the meantime.
1
Changing the value later in the document will not change the definition ofps@myps
explained a lot to me. Very nice!
– Sigur
Nov 8 at 11:46
@Sigur I added some more comments
– egreg
Nov 8 at 11:50
I got it. That is the point,mybool
will not change, because it comes from an option within the class. Thanks.
– Sigur
Nov 8 at 11:57
add a comment |
up vote
7
down vote
accepted
up vote
7
down vote
accepted
The two constructs aren't equivalent.
With
if@mybool
defps@myps{...T...}%
else
defps@myps{...F...}%
fi
you test if@mybool
and define ps@myps
according to its truth value. Changing the value later in the document will not change the definition of ps@myps
.
To the contrary,
defps@myps{%
if@mybool
...A...%
else
...B...%
fi
}
will yield ...A...
or ...B...
according the the truth value of if@mybool
at the time the macro is expanded.
Which one to use depends on what you need to achieve.
With the first definition, if issued when if@mybool
is true,
@myboolfalse
ps@myps
@myboolfalse
ps@myps
will produce ...A...
twice.
With the second definition, the above code would produce first ...B...
and then ...A...
.
If you are writing a package and if@mybool
is set by a package options at runtime, most likely you want to use the first model, as the macro name suggests you're trying to define a page style that probably shouldn't change mid document.
The situation is quite similar to let
and def
. With letmymacroanother
you define mymacro
to be the same another
is at the time the let
instruction is performed.
With defmymacro{another}
, the meaning of another
current at the moment mymacro
is called will be used, which can have changed in the meantime.
The two constructs aren't equivalent.
With
if@mybool
defps@myps{...T...}%
else
defps@myps{...F...}%
fi
you test if@mybool
and define ps@myps
according to its truth value. Changing the value later in the document will not change the definition of ps@myps
.
To the contrary,
defps@myps{%
if@mybool
...A...%
else
...B...%
fi
}
will yield ...A...
or ...B...
according the the truth value of if@mybool
at the time the macro is expanded.
Which one to use depends on what you need to achieve.
With the first definition, if issued when if@mybool
is true,
@myboolfalse
ps@myps
@myboolfalse
ps@myps
will produce ...A...
twice.
With the second definition, the above code would produce first ...B...
and then ...A...
.
If you are writing a package and if@mybool
is set by a package options at runtime, most likely you want to use the first model, as the macro name suggests you're trying to define a page style that probably shouldn't change mid document.
The situation is quite similar to let
and def
. With letmymacroanother
you define mymacro
to be the same another
is at the time the let
instruction is performed.
With defmymacro{another}
, the meaning of another
current at the moment mymacro
is called will be used, which can have changed in the meantime.
edited Nov 8 at 11:50
answered Nov 8 at 11:44
egreg
698k8518553123
698k8518553123
1
Changing the value later in the document will not change the definition ofps@myps
explained a lot to me. Very nice!
– Sigur
Nov 8 at 11:46
@Sigur I added some more comments
– egreg
Nov 8 at 11:50
I got it. That is the point,mybool
will not change, because it comes from an option within the class. Thanks.
– Sigur
Nov 8 at 11:57
add a comment |
1
Changing the value later in the document will not change the definition ofps@myps
explained a lot to me. Very nice!
– Sigur
Nov 8 at 11:46
@Sigur I added some more comments
– egreg
Nov 8 at 11:50
I got it. That is the point,mybool
will not change, because it comes from an option within the class. Thanks.
– Sigur
Nov 8 at 11:57
1
1
Changing the value later in the document will not change the definition of
ps@myps
explained a lot to me. Very nice!– Sigur
Nov 8 at 11:46
Changing the value later in the document will not change the definition of
ps@myps
explained a lot to me. Very nice!– Sigur
Nov 8 at 11:46
@Sigur I added some more comments
– egreg
Nov 8 at 11:50
@Sigur I added some more comments
– egreg
Nov 8 at 11:50
I got it. That is the point,
mybool
will not change, because it comes from an option within the class. Thanks.– Sigur
Nov 8 at 11:57
I got it. That is the point,
mybool
will not change, because it comes from an option within the class. Thanks.– Sigur
Nov 8 at 11:57
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f458967%2fhow-to-use-true-false-inside-definitions%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
They aren't equivalent. The former tests
if@mybool
at definition time, the latter at call time.– egreg
Nov 8 at 11:40
@egreg, oh, I see. But do you have some reason to choose one? I mean, could I get some bug or problem if I choose wrong?
– Sigur
Nov 8 at 11:42
The two constructs do different things, so generally only one is correct according to what you need to do.
– egreg
Nov 8 at 11:45