What are the values for parameters of an edef at the time of definition?
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
Suppose we have the following short document
documentclassarticle
deffoo#1if#1XXelse not Xfi
edefbar#1if#1XXelse not Xfi
begindocument
foo: X = fooX, Y = fooY
bar: X = barX, Y = barY
enddocument
which results in
foo: X = X, Y = not X
bar: X = not X, Y = not X
The first case is quite simple to understand, expansion of foo
happens at the time the macro is called, #1
is replaced by X
or Y
, and the if
is executed with either of these two characters.
What is not so clear is the result of bar
. I understand that the expansion of if
here happens at the time the macro is defined and thus the concrete value of #1
not yet available; TeX leaves "holes" for the parameters in the expanded replacement text to be filled in later when the macro is actually called. But to properly expand the if
here, some value for #1
is needed.
The parameter doesn't seem to be just left empty, otherwise bar
shouldn't give not X
, because if XX
would always be true. They also don't seem to be relax
ed, as
edefbaz#1ifx#1relax yeselse nofi
always gives no
.
Then what values are used for the parameters at the time of definition?
tex-core expansion
add a comment |Â
up vote
4
down vote
favorite
Suppose we have the following short document
documentclassarticle
deffoo#1if#1XXelse not Xfi
edefbar#1if#1XXelse not Xfi
begindocument
foo: X = fooX, Y = fooY
bar: X = barX, Y = barY
enddocument
which results in
foo: X = X, Y = not X
bar: X = not X, Y = not X
The first case is quite simple to understand, expansion of foo
happens at the time the macro is called, #1
is replaced by X
or Y
, and the if
is executed with either of these two characters.
What is not so clear is the result of bar
. I understand that the expansion of if
here happens at the time the macro is defined and thus the concrete value of #1
not yet available; TeX leaves "holes" for the parameters in the expanded replacement text to be filled in later when the macro is actually called. But to properly expand the if
here, some value for #1
is needed.
The parameter doesn't seem to be just left empty, otherwise bar
shouldn't give not X
, because if XX
would always be true. They also don't seem to be relax
ed, as
edefbaz#1ifx#1relax yeselse nofi
always gives no
.
Then what values are used for the parameters at the time of definition?
tex-core expansion
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
Suppose we have the following short document
documentclassarticle
deffoo#1if#1XXelse not Xfi
edefbar#1if#1XXelse not Xfi
begindocument
foo: X = fooX, Y = fooY
bar: X = barX, Y = barY
enddocument
which results in
foo: X = X, Y = not X
bar: X = not X, Y = not X
The first case is quite simple to understand, expansion of foo
happens at the time the macro is called, #1
is replaced by X
or Y
, and the if
is executed with either of these two characters.
What is not so clear is the result of bar
. I understand that the expansion of if
here happens at the time the macro is defined and thus the concrete value of #1
not yet available; TeX leaves "holes" for the parameters in the expanded replacement text to be filled in later when the macro is actually called. But to properly expand the if
here, some value for #1
is needed.
The parameter doesn't seem to be just left empty, otherwise bar
shouldn't give not X
, because if XX
would always be true. They also don't seem to be relax
ed, as
edefbaz#1ifx#1relax yeselse nofi
always gives no
.
Then what values are used for the parameters at the time of definition?
tex-core expansion
Suppose we have the following short document
documentclassarticle
deffoo#1if#1XXelse not Xfi
edefbar#1if#1XXelse not Xfi
begindocument
foo: X = fooX, Y = fooY
bar: X = barX, Y = barY
enddocument
which results in
foo: X = X, Y = not X
bar: X = not X, Y = not X
The first case is quite simple to understand, expansion of foo
happens at the time the macro is called, #1
is replaced by X
or Y
, and the if
is executed with either of these two characters.
What is not so clear is the result of bar
. I understand that the expansion of if
here happens at the time the macro is defined and thus the concrete value of #1
not yet available; TeX leaves "holes" for the parameters in the expanded replacement text to be filled in later when the macro is actually called. But to properly expand the if
here, some value for #1
is needed.
The parameter doesn't seem to be just left empty, otherwise bar
shouldn't give not X
, because if XX
would always be true. They also don't seem to be relax
ed, as
edefbaz#1ifx#1relax yeselse nofi
always gives no
.
Then what values are used for the parameters at the time of definition?
tex-core expansion
tex-core expansion
asked 1 hour ago
siracusa
3,6021926
3,6021926
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
When TeX does edef<macro><parameter text>
1<replacement text>
2 it sets aside the <macro>
the replacement text and 1, then does full expansion to
<replacement text>
until finding the matching 2. Finally it does
def<macro><parameter text><full expansion of the replacement text>
The full expansion of if#1XXelse not Xfi
is not X
, because #
and 1
are different character tokens (by character code).
Thus your edef
becomes the same as
defbar#1not X
As another example,
edefrightbracestringstring}
is perfectly legal, even if it appears to have unbalanced braces, because when the expansion is being done, the first }
has already been tokenized as }
12 when encountered. This proves that TeX doesn't first absorb the whole <replacement text>
, but performs expansion just like in normal circumstances, with the difference that the matching }
2 stops the process and resumes the assignment.
add a comment |Â
up vote
2
down vote
I would say that it compares #
with 1
hance always goes for the false branch. (Compares second test where it compares #
with #
and chooses true branch)
edefbar#1if#1#1 (TRUE)else #1 (FALSE)fi
showbar
edefbar#1if##1 (TRUE)else (FALSE)fi
showbar
bye
Gives
> bar=macro:
#1->#1 (FALSE).
l.3 showbar
> bar=macro:
#1->1 (TRUE).
l.8 showbar
try alsoedefbar#1if###1 (TRUE)else (FALSE)fi
,bar X
.
â jfbu
58 mins ago
Yes, if one tries (withpdftex
)edefbar#1unlessif#1XXelse not Xfi
,showbar
will output thatbar
is a macro doing#1->XX
.
â egreg
46 mins ago
@egreg good test case indeed.
â jfbu
40 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
When TeX does edef<macro><parameter text>
1<replacement text>
2 it sets aside the <macro>
the replacement text and 1, then does full expansion to
<replacement text>
until finding the matching 2. Finally it does
def<macro><parameter text><full expansion of the replacement text>
The full expansion of if#1XXelse not Xfi
is not X
, because #
and 1
are different character tokens (by character code).
Thus your edef
becomes the same as
defbar#1not X
As another example,
edefrightbracestringstring}
is perfectly legal, even if it appears to have unbalanced braces, because when the expansion is being done, the first }
has already been tokenized as }
12 when encountered. This proves that TeX doesn't first absorb the whole <replacement text>
, but performs expansion just like in normal circumstances, with the difference that the matching }
2 stops the process and resumes the assignment.
add a comment |Â
up vote
3
down vote
When TeX does edef<macro><parameter text>
1<replacement text>
2 it sets aside the <macro>
the replacement text and 1, then does full expansion to
<replacement text>
until finding the matching 2. Finally it does
def<macro><parameter text><full expansion of the replacement text>
The full expansion of if#1XXelse not Xfi
is not X
, because #
and 1
are different character tokens (by character code).
Thus your edef
becomes the same as
defbar#1not X
As another example,
edefrightbracestringstring}
is perfectly legal, even if it appears to have unbalanced braces, because when the expansion is being done, the first }
has already been tokenized as }
12 when encountered. This proves that TeX doesn't first absorb the whole <replacement text>
, but performs expansion just like in normal circumstances, with the difference that the matching }
2 stops the process and resumes the assignment.
add a comment |Â
up vote
3
down vote
up vote
3
down vote
When TeX does edef<macro><parameter text>
1<replacement text>
2 it sets aside the <macro>
the replacement text and 1, then does full expansion to
<replacement text>
until finding the matching 2. Finally it does
def<macro><parameter text><full expansion of the replacement text>
The full expansion of if#1XXelse not Xfi
is not X
, because #
and 1
are different character tokens (by character code).
Thus your edef
becomes the same as
defbar#1not X
As another example,
edefrightbracestringstring}
is perfectly legal, even if it appears to have unbalanced braces, because when the expansion is being done, the first }
has already been tokenized as }
12 when encountered. This proves that TeX doesn't first absorb the whole <replacement text>
, but performs expansion just like in normal circumstances, with the difference that the matching }
2 stops the process and resumes the assignment.
When TeX does edef<macro><parameter text>
1<replacement text>
2 it sets aside the <macro>
the replacement text and 1, then does full expansion to
<replacement text>
until finding the matching 2. Finally it does
def<macro><parameter text><full expansion of the replacement text>
The full expansion of if#1XXelse not Xfi
is not X
, because #
and 1
are different character tokens (by character code).
Thus your edef
becomes the same as
defbar#1not X
As another example,
edefrightbracestringstring}
is perfectly legal, even if it appears to have unbalanced braces, because when the expansion is being done, the first }
has already been tokenized as }
12 when encountered. This proves that TeX doesn't first absorb the whole <replacement text>
, but performs expansion just like in normal circumstances, with the difference that the matching }
2 stops the process and resumes the assignment.
answered 30 mins ago
egreg
685k8418273077
685k8418273077
add a comment |Â
add a comment |Â
up vote
2
down vote
I would say that it compares #
with 1
hance always goes for the false branch. (Compares second test where it compares #
with #
and chooses true branch)
edefbar#1if#1#1 (TRUE)else #1 (FALSE)fi
showbar
edefbar#1if##1 (TRUE)else (FALSE)fi
showbar
bye
Gives
> bar=macro:
#1->#1 (FALSE).
l.3 showbar
> bar=macro:
#1->1 (TRUE).
l.8 showbar
try alsoedefbar#1if###1 (TRUE)else (FALSE)fi
,bar X
.
â jfbu
58 mins ago
Yes, if one tries (withpdftex
)edefbar#1unlessif#1XXelse not Xfi
,showbar
will output thatbar
is a macro doing#1->XX
.
â egreg
46 mins ago
@egreg good test case indeed.
â jfbu
40 mins ago
add a comment |Â
up vote
2
down vote
I would say that it compares #
with 1
hance always goes for the false branch. (Compares second test where it compares #
with #
and chooses true branch)
edefbar#1if#1#1 (TRUE)else #1 (FALSE)fi
showbar
edefbar#1if##1 (TRUE)else (FALSE)fi
showbar
bye
Gives
> bar=macro:
#1->#1 (FALSE).
l.3 showbar
> bar=macro:
#1->1 (TRUE).
l.8 showbar
try alsoedefbar#1if###1 (TRUE)else (FALSE)fi
,bar X
.
â jfbu
58 mins ago
Yes, if one tries (withpdftex
)edefbar#1unlessif#1XXelse not Xfi
,showbar
will output thatbar
is a macro doing#1->XX
.
â egreg
46 mins ago
@egreg good test case indeed.
â jfbu
40 mins ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
I would say that it compares #
with 1
hance always goes for the false branch. (Compares second test where it compares #
with #
and chooses true branch)
edefbar#1if#1#1 (TRUE)else #1 (FALSE)fi
showbar
edefbar#1if##1 (TRUE)else (FALSE)fi
showbar
bye
Gives
> bar=macro:
#1->#1 (FALSE).
l.3 showbar
> bar=macro:
#1->1 (TRUE).
l.8 showbar
I would say that it compares #
with 1
hance always goes for the false branch. (Compares second test where it compares #
with #
and chooses true branch)
edefbar#1if#1#1 (TRUE)else #1 (FALSE)fi
showbar
edefbar#1if##1 (TRUE)else (FALSE)fi
showbar
bye
Gives
> bar=macro:
#1->#1 (FALSE).
l.3 showbar
> bar=macro:
#1->1 (TRUE).
l.8 showbar
answered 1 hour ago
jfbu
42.3k63136
42.3k63136
try alsoedefbar#1if###1 (TRUE)else (FALSE)fi
,bar X
.
â jfbu
58 mins ago
Yes, if one tries (withpdftex
)edefbar#1unlessif#1XXelse not Xfi
,showbar
will output thatbar
is a macro doing#1->XX
.
â egreg
46 mins ago
@egreg good test case indeed.
â jfbu
40 mins ago
add a comment |Â
try alsoedefbar#1if###1 (TRUE)else (FALSE)fi
,bar X
.
â jfbu
58 mins ago
Yes, if one tries (withpdftex
)edefbar#1unlessif#1XXelse not Xfi
,showbar
will output thatbar
is a macro doing#1->XX
.
â egreg
46 mins ago
@egreg good test case indeed.
â jfbu
40 mins ago
try also
edefbar#1if###1 (TRUE)else (FALSE)fi
, bar X
.â jfbu
58 mins ago
try also
edefbar#1if###1 (TRUE)else (FALSE)fi
, bar X
.â jfbu
58 mins ago
Yes, if one tries (with
pdftex
) edefbar#1unlessif#1XXelse not Xfi
, showbar
will output that bar
is a macro doing #1->XX
.â egreg
46 mins ago
Yes, if one tries (with
pdftex
) edefbar#1unlessif#1XXelse not Xfi
, showbar
will output that bar
is a macro doing #1->XX
.â egreg
46 mins ago
@egreg good test case indeed.
â jfbu
40 mins ago
@egreg good test case indeed.
â jfbu
40 mins 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%2f452947%2fwhat-are-the-values-for-parameters-of-an-edef-at-the-time-of-definition%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