How to use true/false inside definitions?

The name of the pictureThe name of the pictureThe name of the pictureClash 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










share|improve this question



















  • 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














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










share|improve this question



















  • 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












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










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago

























asked 1 hour ago









Sigur

22.7k353134




22.7k353134







  • 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












  • 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







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










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.






share|improve this answer


















  • 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










  • @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










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',
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
);



);













 

draft saved


draft discarded


















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






























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.






share|improve this answer


















  • 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










  • @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














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.






share|improve this answer


















  • 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










  • @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












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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








edited 1 hour ago

























answered 1 hour ago









egreg

695k8518453102




695k8518453102







  • 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










  • @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




    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










  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

List of Gilmore Girls characters

Confectionery