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
}









share|improve this question




















  • 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















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
}









share|improve this question




















  • 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













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
}









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 Nov 8 at 11:44

























asked Nov 8 at 11:38









Sigur

23.1k353134




23.1k353134








  • 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














  • 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








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










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.






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











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















Required, but never shown

























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.






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















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.






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













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.






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 defmymacro{another}, 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 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 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










  • 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




    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










  • 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


















 

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















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







Popular posts from this blog

Schultheiß

Liste der Kulturdenkmale in Wilsdruff

Android Play Services Check