Seemingly unused edef prior to an ifx mysteriously affects the outcome of the ifx. Why?Why does this simple...
web3.py web3.isConnected() returns false always
How does a program know if stdout is connected to a terminal or a pipe?
Does a semiconductor follow Ohm's law?
Is it idiomatic to construct against `this`?
Seemingly unused edef prior to an ifx mysteriously affects the outcome of the ifx. Why?
Is there really no use for MD5 anymore?
Why was the Spitfire's elliptical wing almost uncopied by other aircraft of World War 2?
How come there are so many candidates for the 2020 Democratic party presidential nomination?
Do I have an "anti-research" personality?
In order to check if a field is required or not, is the result of isNillable method sufficient?
The Defining Moment
Does Gita support doctrine of eternal cycle of birth and death for evil people?
Pulling the rope with one hand is as heavy as with two hands?
Contradiction proof for inequality of P and NP?
Minor Revision with suggestion of an alternative proof by reviewer
Why did C use the -> operator instead of reusing the . operator?
Exchange,swap or switch
How can Zone of Truth be defeated without the caster knowing?
How can Republicans who favour free markets, consistently express anger when they don't like the outcome of that choice?
Can SQL Server create collisions in system generated constraint names?
How to write a column outside the braces in a matrix?
French for 'It must be my imagination'?
A strange hotel
Phrase for the opposite of "foolproof"
Seemingly unused edef prior to an ifx mysteriously affects the outcome of the ifx. Why?
Why does this simple ifx test fail?How to display some text based on a condition inside a tabular environment?Macro to do nothing via a defPreserving (and Controlling) ExpandednessWhy does this use of `expandafter` not work?Pre-expansion of moving macro argumentUsing MakeUppercase on expanded macro with argumentDefining an anaphoric macro to define multiple commands based on a templatestoring snapshot of a rapidly changing commandThe laws of expansion (chardeffoo=<number>foo)Why can I not use string to prevent the expansion of csname?
It is my understanding that in ifxxy xx else yy fi
, ifx
does NOT expand its arguments. If you want ifx
to compare the expanded values of x
and y
, then we need to do the expansion ourselves before feeding them to ifx
:
edefxpndX{x}
edefxpndY{y}
ifxxpndXxpndY xx else yy fi
asedef
does this expansion for us. This is frequently the case when x
and y
are the arguments in a macro so we really have no idea what kind of quantity they represent.
I was adapting a code snippet I found in user2478's answer to the TeX-SE question Why does this simple ifx test fail? and came up with the following MWE:
documentclass{article}
usepackage[svgnames]{xcolor} % to get named colors
begin{document}
chardefmysteryletter=`H
% loop through A-Z to find out the mystery letter
newcountcurrentchar
currentchar=`A
loop
chardeftemp=thecurrentchar
edeftmp{temp}%
ifxmysterylettertemp {color{Red}bftemp}elsetempfi
advance currentchar by 1
unlessifnum currentchar>90
repeat
end{document}
which, when compiled, generated the output:
which actually is the desired output, but it should NOT have been! I added the statement edeftmp{temp}
to get the 'expanded' version of temp
intending to change the temp
argument to the ifx
command to tmp
but had not when this document was compiled. Low and behold, the desired result was printed out! This lead me to believe that the expansion performed by the edeftmp{temp}
statement was not required, so it was commented out and the document recompiled. This gave the wrong result; the letter H was not bold or red
I note that removing the comment character from the end of the edef
command had the expected affect of adding a space between each letter, but did not prevent the 'H' from being found and highlighted.
So my question is this: How does the unused expansion of temp
by the edef
statement change the comparison performed by the ifx
command? What am I missing here?
macros conditionals expansion
New contributor
add a comment |
It is my understanding that in ifxxy xx else yy fi
, ifx
does NOT expand its arguments. If you want ifx
to compare the expanded values of x
and y
, then we need to do the expansion ourselves before feeding them to ifx
:
edefxpndX{x}
edefxpndY{y}
ifxxpndXxpndY xx else yy fi
asedef
does this expansion for us. This is frequently the case when x
and y
are the arguments in a macro so we really have no idea what kind of quantity they represent.
I was adapting a code snippet I found in user2478's answer to the TeX-SE question Why does this simple ifx test fail? and came up with the following MWE:
documentclass{article}
usepackage[svgnames]{xcolor} % to get named colors
begin{document}
chardefmysteryletter=`H
% loop through A-Z to find out the mystery letter
newcountcurrentchar
currentchar=`A
loop
chardeftemp=thecurrentchar
edeftmp{temp}%
ifxmysterylettertemp {color{Red}bftemp}elsetempfi
advance currentchar by 1
unlessifnum currentchar>90
repeat
end{document}
which, when compiled, generated the output:
which actually is the desired output, but it should NOT have been! I added the statement edeftmp{temp}
to get the 'expanded' version of temp
intending to change the temp
argument to the ifx
command to tmp
but had not when this document was compiled. Low and behold, the desired result was printed out! This lead me to believe that the expansion performed by the edeftmp{temp}
statement was not required, so it was commented out and the document recompiled. This gave the wrong result; the letter H was not bold or red
I note that removing the comment character from the end of the edef
command had the expected affect of adding a space between each letter, but did not prevent the 'H' from being found and highlighted.
So my question is this: How does the unused expansion of temp
by the edef
statement change the comparison performed by the ifx
command? What am I missing here?
macros conditionals expansion
New contributor
add a comment |
It is my understanding that in ifxxy xx else yy fi
, ifx
does NOT expand its arguments. If you want ifx
to compare the expanded values of x
and y
, then we need to do the expansion ourselves before feeding them to ifx
:
edefxpndX{x}
edefxpndY{y}
ifxxpndXxpndY xx else yy fi
asedef
does this expansion for us. This is frequently the case when x
and y
are the arguments in a macro so we really have no idea what kind of quantity they represent.
I was adapting a code snippet I found in user2478's answer to the TeX-SE question Why does this simple ifx test fail? and came up with the following MWE:
documentclass{article}
usepackage[svgnames]{xcolor} % to get named colors
begin{document}
chardefmysteryletter=`H
% loop through A-Z to find out the mystery letter
newcountcurrentchar
currentchar=`A
loop
chardeftemp=thecurrentchar
edeftmp{temp}%
ifxmysterylettertemp {color{Red}bftemp}elsetempfi
advance currentchar by 1
unlessifnum currentchar>90
repeat
end{document}
which, when compiled, generated the output:
which actually is the desired output, but it should NOT have been! I added the statement edeftmp{temp}
to get the 'expanded' version of temp
intending to change the temp
argument to the ifx
command to tmp
but had not when this document was compiled. Low and behold, the desired result was printed out! This lead me to believe that the expansion performed by the edeftmp{temp}
statement was not required, so it was commented out and the document recompiled. This gave the wrong result; the letter H was not bold or red
I note that removing the comment character from the end of the edef
command had the expected affect of adding a space between each letter, but did not prevent the 'H' from being found and highlighted.
So my question is this: How does the unused expansion of temp
by the edef
statement change the comparison performed by the ifx
command? What am I missing here?
macros conditionals expansion
New contributor
It is my understanding that in ifxxy xx else yy fi
, ifx
does NOT expand its arguments. If you want ifx
to compare the expanded values of x
and y
, then we need to do the expansion ourselves before feeding them to ifx
:
edefxpndX{x}
edefxpndY{y}
ifxxpndXxpndY xx else yy fi
asedef
does this expansion for us. This is frequently the case when x
and y
are the arguments in a macro so we really have no idea what kind of quantity they represent.
I was adapting a code snippet I found in user2478's answer to the TeX-SE question Why does this simple ifx test fail? and came up with the following MWE:
documentclass{article}
usepackage[svgnames]{xcolor} % to get named colors
begin{document}
chardefmysteryletter=`H
% loop through A-Z to find out the mystery letter
newcountcurrentchar
currentchar=`A
loop
chardeftemp=thecurrentchar
edeftmp{temp}%
ifxmysterylettertemp {color{Red}bftemp}elsetempfi
advance currentchar by 1
unlessifnum currentchar>90
repeat
end{document}
which, when compiled, generated the output:
which actually is the desired output, but it should NOT have been! I added the statement edeftmp{temp}
to get the 'expanded' version of temp
intending to change the temp
argument to the ifx
command to tmp
but had not when this document was compiled. Low and behold, the desired result was printed out! This lead me to believe that the expansion performed by the edeftmp{temp}
statement was not required, so it was commented out and the document recompiled. This gave the wrong result; the letter H was not bold or red
I note that removing the comment character from the end of the edef
command had the expected affect of adding a space between each letter, but did not prevent the 'H' from being found and highlighted.
So my question is this: How does the unused expansion of temp
by the edef
statement change the comparison performed by the ifx
command? What am I missing here?
macros conditionals expansion
macros conditionals expansion
New contributor
New contributor
edited 1 hour ago
David Carlisle
501k4211481897
501k4211481897
New contributor
asked 2 hours ago
OneMugOneMug
163
163
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
chardeftemp=thecurrentchar
edeftmp{temp}%
tokens defined via chardef
are not expandable, so edeftmp{temp}
is the same as deftmp{temp}
It is not clear why you do not expect ifxmysterylettertemp
not to be true if the two tokens are both defined via chardef
with the same number?
I guess your modified version was equivalent to
chardeftemp=thecurrentchar
ifxmysterylettertemp
There the ifx
test happens before the assignment while looking to end the number, you need
chardeftemp=thecurrentcharrelax
ifxmysterylettertemp
or
chardeftemp=currentchar
ifxmysterylettertemp
So your edef
was just acting like relax
terminating the chardef
assignment.
Thanks for the fast response. Still trying to figure out how to use the TeX-SE question and comment editors, please be patient. I had planned on converting this snippet into adefscanAlpha#1{...
so I coded it the way I did expecting the macro argument to be used in theifx
to be somewhat unknown at execution time, say be usingscanAlpha{X}
which would make the argument to theifx
different from using thechardef
as in the snippet.
– OneMug
1 hour ago
As stated, removing theedef
and using eitherchardeftemp=thecurrentcharrelax
orchardeftemp=currentchar
works just fine. Aah, such are the mysteries ofrelax
ing. Not sure if I will ever figure out how torelax
. Thanks again for this answer.
– OneMug
1 hour ago
1
@OneMugit'its not really therelax
just that expansion happens when looking for a number,count0=1ifx ab 2else 3fi
sets count0 to 13 with the ifx test happening before the assignment, butcount0=1 ifx ab 2else 3fi
sets count0 to 1
– David Carlisle
51 mins ago
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
OneMug 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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f487937%2fseemingly-unused-edef-prior-to-an-ifx-mysteriously-affects-the-outcome-of-the%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
chardeftemp=thecurrentchar
edeftmp{temp}%
tokens defined via chardef
are not expandable, so edeftmp{temp}
is the same as deftmp{temp}
It is not clear why you do not expect ifxmysterylettertemp
not to be true if the two tokens are both defined via chardef
with the same number?
I guess your modified version was equivalent to
chardeftemp=thecurrentchar
ifxmysterylettertemp
There the ifx
test happens before the assignment while looking to end the number, you need
chardeftemp=thecurrentcharrelax
ifxmysterylettertemp
or
chardeftemp=currentchar
ifxmysterylettertemp
So your edef
was just acting like relax
terminating the chardef
assignment.
Thanks for the fast response. Still trying to figure out how to use the TeX-SE question and comment editors, please be patient. I had planned on converting this snippet into adefscanAlpha#1{...
so I coded it the way I did expecting the macro argument to be used in theifx
to be somewhat unknown at execution time, say be usingscanAlpha{X}
which would make the argument to theifx
different from using thechardef
as in the snippet.
– OneMug
1 hour ago
As stated, removing theedef
and using eitherchardeftemp=thecurrentcharrelax
orchardeftemp=currentchar
works just fine. Aah, such are the mysteries ofrelax
ing. Not sure if I will ever figure out how torelax
. Thanks again for this answer.
– OneMug
1 hour ago
1
@OneMugit'its not really therelax
just that expansion happens when looking for a number,count0=1ifx ab 2else 3fi
sets count0 to 13 with the ifx test happening before the assignment, butcount0=1 ifx ab 2else 3fi
sets count0 to 1
– David Carlisle
51 mins ago
add a comment |
chardeftemp=thecurrentchar
edeftmp{temp}%
tokens defined via chardef
are not expandable, so edeftmp{temp}
is the same as deftmp{temp}
It is not clear why you do not expect ifxmysterylettertemp
not to be true if the two tokens are both defined via chardef
with the same number?
I guess your modified version was equivalent to
chardeftemp=thecurrentchar
ifxmysterylettertemp
There the ifx
test happens before the assignment while looking to end the number, you need
chardeftemp=thecurrentcharrelax
ifxmysterylettertemp
or
chardeftemp=currentchar
ifxmysterylettertemp
So your edef
was just acting like relax
terminating the chardef
assignment.
Thanks for the fast response. Still trying to figure out how to use the TeX-SE question and comment editors, please be patient. I had planned on converting this snippet into adefscanAlpha#1{...
so I coded it the way I did expecting the macro argument to be used in theifx
to be somewhat unknown at execution time, say be usingscanAlpha{X}
which would make the argument to theifx
different from using thechardef
as in the snippet.
– OneMug
1 hour ago
As stated, removing theedef
and using eitherchardeftemp=thecurrentcharrelax
orchardeftemp=currentchar
works just fine. Aah, such are the mysteries ofrelax
ing. Not sure if I will ever figure out how torelax
. Thanks again for this answer.
– OneMug
1 hour ago
1
@OneMugit'its not really therelax
just that expansion happens when looking for a number,count0=1ifx ab 2else 3fi
sets count0 to 13 with the ifx test happening before the assignment, butcount0=1 ifx ab 2else 3fi
sets count0 to 1
– David Carlisle
51 mins ago
add a comment |
chardeftemp=thecurrentchar
edeftmp{temp}%
tokens defined via chardef
are not expandable, so edeftmp{temp}
is the same as deftmp{temp}
It is not clear why you do not expect ifxmysterylettertemp
not to be true if the two tokens are both defined via chardef
with the same number?
I guess your modified version was equivalent to
chardeftemp=thecurrentchar
ifxmysterylettertemp
There the ifx
test happens before the assignment while looking to end the number, you need
chardeftemp=thecurrentcharrelax
ifxmysterylettertemp
or
chardeftemp=currentchar
ifxmysterylettertemp
So your edef
was just acting like relax
terminating the chardef
assignment.
chardeftemp=thecurrentchar
edeftmp{temp}%
tokens defined via chardef
are not expandable, so edeftmp{temp}
is the same as deftmp{temp}
It is not clear why you do not expect ifxmysterylettertemp
not to be true if the two tokens are both defined via chardef
with the same number?
I guess your modified version was equivalent to
chardeftemp=thecurrentchar
ifxmysterylettertemp
There the ifx
test happens before the assignment while looking to end the number, you need
chardeftemp=thecurrentcharrelax
ifxmysterylettertemp
or
chardeftemp=currentchar
ifxmysterylettertemp
So your edef
was just acting like relax
terminating the chardef
assignment.
edited 1 hour ago
answered 1 hour ago
David CarlisleDavid Carlisle
501k4211481897
501k4211481897
Thanks for the fast response. Still trying to figure out how to use the TeX-SE question and comment editors, please be patient. I had planned on converting this snippet into adefscanAlpha#1{...
so I coded it the way I did expecting the macro argument to be used in theifx
to be somewhat unknown at execution time, say be usingscanAlpha{X}
which would make the argument to theifx
different from using thechardef
as in the snippet.
– OneMug
1 hour ago
As stated, removing theedef
and using eitherchardeftemp=thecurrentcharrelax
orchardeftemp=currentchar
works just fine. Aah, such are the mysteries ofrelax
ing. Not sure if I will ever figure out how torelax
. Thanks again for this answer.
– OneMug
1 hour ago
1
@OneMugit'its not really therelax
just that expansion happens when looking for a number,count0=1ifx ab 2else 3fi
sets count0 to 13 with the ifx test happening before the assignment, butcount0=1 ifx ab 2else 3fi
sets count0 to 1
– David Carlisle
51 mins ago
add a comment |
Thanks for the fast response. Still trying to figure out how to use the TeX-SE question and comment editors, please be patient. I had planned on converting this snippet into adefscanAlpha#1{...
so I coded it the way I did expecting the macro argument to be used in theifx
to be somewhat unknown at execution time, say be usingscanAlpha{X}
which would make the argument to theifx
different from using thechardef
as in the snippet.
– OneMug
1 hour ago
As stated, removing theedef
and using eitherchardeftemp=thecurrentcharrelax
orchardeftemp=currentchar
works just fine. Aah, such are the mysteries ofrelax
ing. Not sure if I will ever figure out how torelax
. Thanks again for this answer.
– OneMug
1 hour ago
1
@OneMugit'its not really therelax
just that expansion happens when looking for a number,count0=1ifx ab 2else 3fi
sets count0 to 13 with the ifx test happening before the assignment, butcount0=1 ifx ab 2else 3fi
sets count0 to 1
– David Carlisle
51 mins ago
Thanks for the fast response. Still trying to figure out how to use the TeX-SE question and comment editors, please be patient. I had planned on converting this snippet into a
defscanAlpha#1{...
so I coded it the way I did expecting the macro argument to be used in the ifx
to be somewhat unknown at execution time, say be using scanAlpha{X}
which would make the argument to the ifx
different from using the chardef
as in the snippet.– OneMug
1 hour ago
Thanks for the fast response. Still trying to figure out how to use the TeX-SE question and comment editors, please be patient. I had planned on converting this snippet into a
defscanAlpha#1{...
so I coded it the way I did expecting the macro argument to be used in the ifx
to be somewhat unknown at execution time, say be using scanAlpha{X}
which would make the argument to the ifx
different from using the chardef
as in the snippet.– OneMug
1 hour ago
As stated, removing the
edef
and using either chardeftemp=thecurrentcharrelax
or chardeftemp=currentchar
works just fine. Aah, such are the mysteries of relax
ing. Not sure if I will ever figure out how to relax
. Thanks again for this answer.– OneMug
1 hour ago
As stated, removing the
edef
and using either chardeftemp=thecurrentcharrelax
or chardeftemp=currentchar
works just fine. Aah, such are the mysteries of relax
ing. Not sure if I will ever figure out how to relax
. Thanks again for this answer.– OneMug
1 hour ago
1
1
@OneMugit'its not really the
relax
just that expansion happens when looking for a number, count0=1ifx ab 2else 3fi
sets count0 to 13 with the ifx test happening before the assignment, but count0=1 ifx ab 2else 3fi
sets count0 to 1– David Carlisle
51 mins ago
@OneMugit'its not really the
relax
just that expansion happens when looking for a number, count0=1ifx ab 2else 3fi
sets count0 to 13 with the ifx test happening before the assignment, but count0=1 ifx ab 2else 3fi
sets count0 to 1– David Carlisle
51 mins ago
add a comment |
OneMug is a new contributor. Be nice, and check out our Code of Conduct.
OneMug is a new contributor. Be nice, and check out our Code of Conduct.
OneMug is a new contributor. Be nice, and check out our Code of Conduct.
OneMug is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f487937%2fseemingly-unused-edef-prior-to-an-ifx-mysteriously-affects-the-outcome-of-the%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