How to use true/false inside definitions?
Clash Royale CLAN TAG#URR8PPP
up vote
3
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
3
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
1
They aren't equivalent. The former testsif@mybool
at definition time, the latter at call time.
– egreg
1 hour ago
@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
1 hour ago
The two constructs do different things, so generally only one is correct according to what you need to do.
– egreg
1 hour ago
add a comment |Â
up vote
3
down vote
favorite
up vote
3
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 1 hour ago
asked 1 hour ago
Sigur
22.7k353134
22.7k353134
1
They aren't equivalent. The former testsif@mybool
at definition time, the latter at call time.
– egreg
1 hour ago
@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
1 hour ago
The two constructs do different things, so generally only one is correct according to what you need to do.
– egreg
1 hour ago
add a comment |Â
1
They aren't equivalent. The former testsif@mybool
at definition time, the latter at call time.
– egreg
1 hour ago
@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
1 hour ago
The two constructs do different things, so generally only one is correct according to what you need to do.
– egreg
1 hour ago
1
1
They aren't equivalent. The former tests
if@mybool
at definition time, the latter at call time.– egreg
1 hour ago
They aren't equivalent. The former tests
if@mybool
at definition time, the latter at call time.– egreg
1 hour ago
@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
1 hour ago
@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
1 hour ago
The two constructs do different things, so generally only one is correct according to what you need to do.
– egreg
1 hour ago
The two constructs do different things, so generally only one is correct according to what you need to do.
– egreg
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
5
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 defmymacroanother
, 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
1 hour ago
@Sigur I added some more comments
– egreg
1 hour ago
I got it. That is the point,mybool
will not change, because it comes from an option within the class. Thanks.
– Sigur
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
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 defmymacroanother
, 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
1 hour ago
@Sigur I added some more comments
– egreg
1 hour ago
I got it. That is the point,mybool
will not change, because it comes from an option within the class. Thanks.
– Sigur
1 hour ago
add a comment |Â
up vote
5
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 defmymacroanother
, 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
1 hour ago
@Sigur I added some more comments
– egreg
1 hour ago
I got it. That is the point,mybool
will not change, because it comes from an option within the class. Thanks.
– Sigur
1 hour ago
add a comment |Â
up vote
5
down vote
accepted
up vote
5
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 defmymacroanother
, 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 defmymacroanother
, the meaning of another
current at the moment mymacro
is called will be used, which can have changed in the meantime.
edited 1 hour ago
answered 1 hour ago


egreg
695k8518453102
695k8518453102
1
Changing the value later in the document will not change the definition ofps@myps
explained a lot to me. Very nice!
– Sigur
1 hour ago
@Sigur I added some more comments
– egreg
1 hour ago
I got it. That is the point,mybool
will not change, because it comes from an option within the class. Thanks.
– Sigur
1 hour ago
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
1 hour ago
@Sigur I added some more comments
– egreg
1 hour ago
I got it. That is the point,mybool
will not change, because it comes from an option within the class. Thanks.
– Sigur
1 hour ago
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
1 hour ago
Changing the value later in the document will not change the definition of
ps@myps
explained a lot to me. Very nice!– Sigur
1 hour ago
@Sigur I added some more comments
– egreg
1 hour ago
@Sigur I added some more comments
– egreg
1 hour ago
I got it. That is the point,
mybool
will not change, because it comes from an option within the class. Thanks.– Sigur
1 hour ago
I got it. That is the point,
mybool
will not change, because it comes from an option within the class. Thanks.– Sigur
1 hour ago
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%2f458967%2fhow-to-use-true-false-inside-definitions%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
1
They aren't equivalent. The former tests
if@mybool
at definition time, the latter at call time.– egreg
1 hour ago
@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
1 hour ago
The two constructs do different things, so generally only one is correct according to what you need to do.
– egreg
1 hour ago