What is the difference between unexpanded and protected in ConTeXt?
Clash Royale CLAN TAG#URR8PPP
up vote
7
down vote
favorite
EDIT: It turns out that unexpanded
in ConTeXt is different from unexpanded
in ε-TeX, so the earlier description doesn't apply. I'll update the question accordingly.
From the ε-TeX manual:
- Protected macros (defined with the
protected
prefix) are not expanded when building an expanded token list (foredef
,xdef
,message
,errmessage
,special
,mark
,marks
or when writing the token list forwrite
to a file) or when looking ahead in an alignment fornoalign
oromit
.
From the ConTeXt Wiki:
When expansion of a macro gives problems we can precede it by
unexpanded
, like so:
unexpandeddefsomecommand... ... ...
This will prevent the macro from being expanded in places where no typesetting occurs, like when strings are written to the tuo file.
In practice, I've seen the two used in seemingly the exact same situations, although unexpandeddef...
seems more common. Is there any notable difference between the two that I should be aware of?
context expansion e-tex protected-macro
New contributor
G. S. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
7
down vote
favorite
EDIT: It turns out that unexpanded
in ConTeXt is different from unexpanded
in ε-TeX, so the earlier description doesn't apply. I'll update the question accordingly.
From the ε-TeX manual:
- Protected macros (defined with the
protected
prefix) are not expanded when building an expanded token list (foredef
,xdef
,message
,errmessage
,special
,mark
,marks
or when writing the token list forwrite
to a file) or when looking ahead in an alignment fornoalign
oromit
.
From the ConTeXt Wiki:
When expansion of a macro gives problems we can precede it by
unexpanded
, like so:
unexpandeddefsomecommand... ... ...
This will prevent the macro from being expanded in places where no typesetting occurs, like when strings are written to the tuo file.
In practice, I've seen the two used in seemingly the exact same situations, although unexpandeddef...
seems more common. Is there any notable difference between the two that I should be aware of?
context expansion e-tex protected-macro
New contributor
G. S. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
unexpandeddef
is only used by ConTeXt, which has different namings.
– egreg
6 hours ago
I probably should have mentioned in the original post that I'm working with ConTeXt, sorry.
– G. S.
57 mins ago
add a comment |Â
up vote
7
down vote
favorite
up vote
7
down vote
favorite
EDIT: It turns out that unexpanded
in ConTeXt is different from unexpanded
in ε-TeX, so the earlier description doesn't apply. I'll update the question accordingly.
From the ε-TeX manual:
- Protected macros (defined with the
protected
prefix) are not expanded when building an expanded token list (foredef
,xdef
,message
,errmessage
,special
,mark
,marks
or when writing the token list forwrite
to a file) or when looking ahead in an alignment fornoalign
oromit
.
From the ConTeXt Wiki:
When expansion of a macro gives problems we can precede it by
unexpanded
, like so:
unexpandeddefsomecommand... ... ...
This will prevent the macro from being expanded in places where no typesetting occurs, like when strings are written to the tuo file.
In practice, I've seen the two used in seemingly the exact same situations, although unexpandeddef...
seems more common. Is there any notable difference between the two that I should be aware of?
context expansion e-tex protected-macro
New contributor
G. S. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
EDIT: It turns out that unexpanded
in ConTeXt is different from unexpanded
in ε-TeX, so the earlier description doesn't apply. I'll update the question accordingly.
From the ε-TeX manual:
- Protected macros (defined with the
protected
prefix) are not expanded when building an expanded token list (foredef
,xdef
,message
,errmessage
,special
,mark
,marks
or when writing the token list forwrite
to a file) or when looking ahead in an alignment fornoalign
oromit
.
From the ConTeXt Wiki:
When expansion of a macro gives problems we can precede it by
unexpanded
, like so:
unexpandeddefsomecommand... ... ...
This will prevent the macro from being expanded in places where no typesetting occurs, like when strings are written to the tuo file.
In practice, I've seen the two used in seemingly the exact same situations, although unexpandeddef...
seems more common. Is there any notable difference between the two that I should be aware of?
context expansion e-tex protected-macro
context expansion e-tex protected-macro
New contributor
G. S. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
G. S. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 18 mins ago
New contributor
G. S. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 12 hours ago
G. S.
484
484
New contributor
G. S. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
G. S. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
G. S. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
unexpandeddef
is only used by ConTeXt, which has different namings.
– egreg
6 hours ago
I probably should have mentioned in the original post that I'm working with ConTeXt, sorry.
– G. S.
57 mins ago
add a comment |Â
2
unexpandeddef
is only used by ConTeXt, which has different namings.
– egreg
6 hours ago
I probably should have mentioned in the original post that I'm working with ConTeXt, sorry.
– G. S.
57 mins ago
2
2
unexpandeddef
is only used by ConTeXt, which has different namings.– egreg
6 hours ago
unexpandeddef
is only used by ConTeXt, which has different namings.– egreg
6 hours ago
I probably should have mentioned in the original post that I'm working with ConTeXt, sorry.
– G. S.
57 mins ago
I probably should have mentioned in the original post that I'm working with ConTeXt, sorry.
– G. S.
57 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
6
down vote
This is comparing the etex primitive unexpanded
not the context macro of the same name. The Question has since been clarified that the context command was what was intended.
They are not really comparable:
protected
is a modifier of def
and makes the resulting token have an internal flag set so that its expansion is suppressed in certain contexts. So it is a property of the command.
unexpanded
is used to prevent the expansion of a token list so it is a property of the context not of the commands that are in it.
Of course there is some overlap, if you are writing to a file and need to prevent expansion then you could (as in classic latex) declare that fragile commands will fail and so arrange that all definitions are made with protect
so there are less fragile commands. Or you could use unexpanded
and prevent all expansion whether or not the commands are made with protect
, this would also stop any user defined commands expanding to their replacements which may or may not be what you want, depending on circumstances.
@G.S. no that's a syntax error unexpanded works likeedeffoozzz unexpanded... scarymacrohere.. zzz
that is it does the same asthetoks@
in anedef
without the need for using a toks register. It is unrelated to definitions.
– David Carlisle
30 mins ago
Oh I see from comments under the question you are comparing the etex primitiveprotected
to the context macrounexpanded
rather than to the etex primitiveunexpanded
That might explain the question:-)
– David Carlisle
28 mins ago
To use theunexpanded
primitive in ConTeXt you have to usenormalunexpanded
.
– Wolfgang Schuster
24 mins ago
@WolfgangSchuster Thanks, but it turns out I actually meant to ask about ConTeXt'sunexpanded
macro (I've updated the question). Mostly I've been indecisive on whether to addunexpanded
ornormalprotected
before definitions, especially sincesetuvalue
& similar commands defined insyst-aux.mkiv
usenormalprotected
while most other uses ofdef
I've seen in the source code useunexpanded
.
– G. S.
19 mins ago
@G.S. You should ask these questions on the ConTeXt list because only Hans Hagen can give you an answer for this.
– Wolfgang Schuster
16 mins ago
add a comment |Â
up vote
2
down vote
If I compile with context
the following
showunexpanded
I get
> unexpanded=protected
tex error > tex error on line 1 in file /Users/enrico2013/provaccia/sep2018/tttsssttt.tex: ?
l.1 showunexpanded
1 >> showunexpanded
2
In /usr/local/texlive/2018/texmf-dist/tex/context/base/mkiv/syst-aux.mkiv
, line 61 reads
letunexpandednormalprotected
If I add shownormalprotected
, then the output is
> normalprotected=protected
Of course, the meaning of unexpanded
could be reassigned, but macros defined when unexpanded
has that meaning will be protected
(in e-TeX lingo).
I did look throughsyst-aux.mkiv
and found that line, but given David Carlisle's answer and the fact that I get different errors when I useunexpanded
vs.normalprotected
, I'm no longer so sure that they're the same, or whether the ε-TeX definition is still relevant.
– G. S.
31 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
6
down vote
This is comparing the etex primitive unexpanded
not the context macro of the same name. The Question has since been clarified that the context command was what was intended.
They are not really comparable:
protected
is a modifier of def
and makes the resulting token have an internal flag set so that its expansion is suppressed in certain contexts. So it is a property of the command.
unexpanded
is used to prevent the expansion of a token list so it is a property of the context not of the commands that are in it.
Of course there is some overlap, if you are writing to a file and need to prevent expansion then you could (as in classic latex) declare that fragile commands will fail and so arrange that all definitions are made with protect
so there are less fragile commands. Or you could use unexpanded
and prevent all expansion whether or not the commands are made with protect
, this would also stop any user defined commands expanding to their replacements which may or may not be what you want, depending on circumstances.
@G.S. no that's a syntax error unexpanded works likeedeffoozzz unexpanded... scarymacrohere.. zzz
that is it does the same asthetoks@
in anedef
without the need for using a toks register. It is unrelated to definitions.
– David Carlisle
30 mins ago
Oh I see from comments under the question you are comparing the etex primitiveprotected
to the context macrounexpanded
rather than to the etex primitiveunexpanded
That might explain the question:-)
– David Carlisle
28 mins ago
To use theunexpanded
primitive in ConTeXt you have to usenormalunexpanded
.
– Wolfgang Schuster
24 mins ago
@WolfgangSchuster Thanks, but it turns out I actually meant to ask about ConTeXt'sunexpanded
macro (I've updated the question). Mostly I've been indecisive on whether to addunexpanded
ornormalprotected
before definitions, especially sincesetuvalue
& similar commands defined insyst-aux.mkiv
usenormalprotected
while most other uses ofdef
I've seen in the source code useunexpanded
.
– G. S.
19 mins ago
@G.S. You should ask these questions on the ConTeXt list because only Hans Hagen can give you an answer for this.
– Wolfgang Schuster
16 mins ago
add a comment |Â
up vote
6
down vote
This is comparing the etex primitive unexpanded
not the context macro of the same name. The Question has since been clarified that the context command was what was intended.
They are not really comparable:
protected
is a modifier of def
and makes the resulting token have an internal flag set so that its expansion is suppressed in certain contexts. So it is a property of the command.
unexpanded
is used to prevent the expansion of a token list so it is a property of the context not of the commands that are in it.
Of course there is some overlap, if you are writing to a file and need to prevent expansion then you could (as in classic latex) declare that fragile commands will fail and so arrange that all definitions are made with protect
so there are less fragile commands. Or you could use unexpanded
and prevent all expansion whether or not the commands are made with protect
, this would also stop any user defined commands expanding to their replacements which may or may not be what you want, depending on circumstances.
@G.S. no that's a syntax error unexpanded works likeedeffoozzz unexpanded... scarymacrohere.. zzz
that is it does the same asthetoks@
in anedef
without the need for using a toks register. It is unrelated to definitions.
– David Carlisle
30 mins ago
Oh I see from comments under the question you are comparing the etex primitiveprotected
to the context macrounexpanded
rather than to the etex primitiveunexpanded
That might explain the question:-)
– David Carlisle
28 mins ago
To use theunexpanded
primitive in ConTeXt you have to usenormalunexpanded
.
– Wolfgang Schuster
24 mins ago
@WolfgangSchuster Thanks, but it turns out I actually meant to ask about ConTeXt'sunexpanded
macro (I've updated the question). Mostly I've been indecisive on whether to addunexpanded
ornormalprotected
before definitions, especially sincesetuvalue
& similar commands defined insyst-aux.mkiv
usenormalprotected
while most other uses ofdef
I've seen in the source code useunexpanded
.
– G. S.
19 mins ago
@G.S. You should ask these questions on the ConTeXt list because only Hans Hagen can give you an answer for this.
– Wolfgang Schuster
16 mins ago
add a comment |Â
up vote
6
down vote
up vote
6
down vote
This is comparing the etex primitive unexpanded
not the context macro of the same name. The Question has since been clarified that the context command was what was intended.
They are not really comparable:
protected
is a modifier of def
and makes the resulting token have an internal flag set so that its expansion is suppressed in certain contexts. So it is a property of the command.
unexpanded
is used to prevent the expansion of a token list so it is a property of the context not of the commands that are in it.
Of course there is some overlap, if you are writing to a file and need to prevent expansion then you could (as in classic latex) declare that fragile commands will fail and so arrange that all definitions are made with protect
so there are less fragile commands. Or you could use unexpanded
and prevent all expansion whether or not the commands are made with protect
, this would also stop any user defined commands expanding to their replacements which may or may not be what you want, depending on circumstances.
This is comparing the etex primitive unexpanded
not the context macro of the same name. The Question has since been clarified that the context command was what was intended.
They are not really comparable:
protected
is a modifier of def
and makes the resulting token have an internal flag set so that its expansion is suppressed in certain contexts. So it is a property of the command.
unexpanded
is used to prevent the expansion of a token list so it is a property of the context not of the commands that are in it.
Of course there is some overlap, if you are writing to a file and need to prevent expansion then you could (as in classic latex) declare that fragile commands will fail and so arrange that all definitions are made with protect
so there are less fragile commands. Or you could use unexpanded
and prevent all expansion whether or not the commands are made with protect
, this would also stop any user defined commands expanding to their replacements which may or may not be what you want, depending on circumstances.
edited 1 min ago
answered 6 hours ago
David Carlisle
471k3811001829
471k3811001829
@G.S. no that's a syntax error unexpanded works likeedeffoozzz unexpanded... scarymacrohere.. zzz
that is it does the same asthetoks@
in anedef
without the need for using a toks register. It is unrelated to definitions.
– David Carlisle
30 mins ago
Oh I see from comments under the question you are comparing the etex primitiveprotected
to the context macrounexpanded
rather than to the etex primitiveunexpanded
That might explain the question:-)
– David Carlisle
28 mins ago
To use theunexpanded
primitive in ConTeXt you have to usenormalunexpanded
.
– Wolfgang Schuster
24 mins ago
@WolfgangSchuster Thanks, but it turns out I actually meant to ask about ConTeXt'sunexpanded
macro (I've updated the question). Mostly I've been indecisive on whether to addunexpanded
ornormalprotected
before definitions, especially sincesetuvalue
& similar commands defined insyst-aux.mkiv
usenormalprotected
while most other uses ofdef
I've seen in the source code useunexpanded
.
– G. S.
19 mins ago
@G.S. You should ask these questions on the ConTeXt list because only Hans Hagen can give you an answer for this.
– Wolfgang Schuster
16 mins ago
add a comment |Â
@G.S. no that's a syntax error unexpanded works likeedeffoozzz unexpanded... scarymacrohere.. zzz
that is it does the same asthetoks@
in anedef
without the need for using a toks register. It is unrelated to definitions.
– David Carlisle
30 mins ago
Oh I see from comments under the question you are comparing the etex primitiveprotected
to the context macrounexpanded
rather than to the etex primitiveunexpanded
That might explain the question:-)
– David Carlisle
28 mins ago
To use theunexpanded
primitive in ConTeXt you have to usenormalunexpanded
.
– Wolfgang Schuster
24 mins ago
@WolfgangSchuster Thanks, but it turns out I actually meant to ask about ConTeXt'sunexpanded
macro (I've updated the question). Mostly I've been indecisive on whether to addunexpanded
ornormalprotected
before definitions, especially sincesetuvalue
& similar commands defined insyst-aux.mkiv
usenormalprotected
while most other uses ofdef
I've seen in the source code useunexpanded
.
– G. S.
19 mins ago
@G.S. You should ask these questions on the ConTeXt list because only Hans Hagen can give you an answer for this.
– Wolfgang Schuster
16 mins ago
@G.S. no that's a syntax error unexpanded works like
edeffoozzz unexpanded... scarymacrohere.. zzz
that is it does the same as thetoks@
in an edef
without the need for using a toks register. It is unrelated to definitions.– David Carlisle
30 mins ago
@G.S. no that's a syntax error unexpanded works like
edeffoozzz unexpanded... scarymacrohere.. zzz
that is it does the same as thetoks@
in an edef
without the need for using a toks register. It is unrelated to definitions.– David Carlisle
30 mins ago
Oh I see from comments under the question you are comparing the etex primitive
protected
to the context macro unexpanded
rather than to the etex primitive unexpanded
That might explain the question:-)– David Carlisle
28 mins ago
Oh I see from comments under the question you are comparing the etex primitive
protected
to the context macro unexpanded
rather than to the etex primitive unexpanded
That might explain the question:-)– David Carlisle
28 mins ago
To use the
unexpanded
primitive in ConTeXt you have to use normalunexpanded
.– Wolfgang Schuster
24 mins ago
To use the
unexpanded
primitive in ConTeXt you have to use normalunexpanded
.– Wolfgang Schuster
24 mins ago
@WolfgangSchuster Thanks, but it turns out I actually meant to ask about ConTeXt's
unexpanded
macro (I've updated the question). Mostly I've been indecisive on whether to add unexpanded
or normalprotected
before definitions, especially since setuvalue
& similar commands defined in syst-aux.mkiv
use normalprotected
while most other uses of def
I've seen in the source code use unexpanded
.– G. S.
19 mins ago
@WolfgangSchuster Thanks, but it turns out I actually meant to ask about ConTeXt's
unexpanded
macro (I've updated the question). Mostly I've been indecisive on whether to add unexpanded
or normalprotected
before definitions, especially since setuvalue
& similar commands defined in syst-aux.mkiv
use normalprotected
while most other uses of def
I've seen in the source code use unexpanded
.– G. S.
19 mins ago
@G.S. You should ask these questions on the ConTeXt list because only Hans Hagen can give you an answer for this.
– Wolfgang Schuster
16 mins ago
@G.S. You should ask these questions on the ConTeXt list because only Hans Hagen can give you an answer for this.
– Wolfgang Schuster
16 mins ago
add a comment |Â
up vote
2
down vote
If I compile with context
the following
showunexpanded
I get
> unexpanded=protected
tex error > tex error on line 1 in file /Users/enrico2013/provaccia/sep2018/tttsssttt.tex: ?
l.1 showunexpanded
1 >> showunexpanded
2
In /usr/local/texlive/2018/texmf-dist/tex/context/base/mkiv/syst-aux.mkiv
, line 61 reads
letunexpandednormalprotected
If I add shownormalprotected
, then the output is
> normalprotected=protected
Of course, the meaning of unexpanded
could be reassigned, but macros defined when unexpanded
has that meaning will be protected
(in e-TeX lingo).
I did look throughsyst-aux.mkiv
and found that line, but given David Carlisle's answer and the fact that I get different errors when I useunexpanded
vs.normalprotected
, I'm no longer so sure that they're the same, or whether the ε-TeX definition is still relevant.
– G. S.
31 mins ago
add a comment |Â
up vote
2
down vote
If I compile with context
the following
showunexpanded
I get
> unexpanded=protected
tex error > tex error on line 1 in file /Users/enrico2013/provaccia/sep2018/tttsssttt.tex: ?
l.1 showunexpanded
1 >> showunexpanded
2
In /usr/local/texlive/2018/texmf-dist/tex/context/base/mkiv/syst-aux.mkiv
, line 61 reads
letunexpandednormalprotected
If I add shownormalprotected
, then the output is
> normalprotected=protected
Of course, the meaning of unexpanded
could be reassigned, but macros defined when unexpanded
has that meaning will be protected
(in e-TeX lingo).
I did look throughsyst-aux.mkiv
and found that line, but given David Carlisle's answer and the fact that I get different errors when I useunexpanded
vs.normalprotected
, I'm no longer so sure that they're the same, or whether the ε-TeX definition is still relevant.
– G. S.
31 mins ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
If I compile with context
the following
showunexpanded
I get
> unexpanded=protected
tex error > tex error on line 1 in file /Users/enrico2013/provaccia/sep2018/tttsssttt.tex: ?
l.1 showunexpanded
1 >> showunexpanded
2
In /usr/local/texlive/2018/texmf-dist/tex/context/base/mkiv/syst-aux.mkiv
, line 61 reads
letunexpandednormalprotected
If I add shownormalprotected
, then the output is
> normalprotected=protected
Of course, the meaning of unexpanded
could be reassigned, but macros defined when unexpanded
has that meaning will be protected
(in e-TeX lingo).
If I compile with context
the following
showunexpanded
I get
> unexpanded=protected
tex error > tex error on line 1 in file /Users/enrico2013/provaccia/sep2018/tttsssttt.tex: ?
l.1 showunexpanded
1 >> showunexpanded
2
In /usr/local/texlive/2018/texmf-dist/tex/context/base/mkiv/syst-aux.mkiv
, line 61 reads
letunexpandednormalprotected
If I add shownormalprotected
, then the output is
> normalprotected=protected
Of course, the meaning of unexpanded
could be reassigned, but macros defined when unexpanded
has that meaning will be protected
(in e-TeX lingo).
answered 35 mins ago


egreg
689k8518333082
689k8518333082
I did look throughsyst-aux.mkiv
and found that line, but given David Carlisle's answer and the fact that I get different errors when I useunexpanded
vs.normalprotected
, I'm no longer so sure that they're the same, or whether the ε-TeX definition is still relevant.
– G. S.
31 mins ago
add a comment |Â
I did look throughsyst-aux.mkiv
and found that line, but given David Carlisle's answer and the fact that I get different errors when I useunexpanded
vs.normalprotected
, I'm no longer so sure that they're the same, or whether the ε-TeX definition is still relevant.
– G. S.
31 mins ago
I did look through
syst-aux.mkiv
and found that line, but given David Carlisle's answer and the fact that I get different errors when I use unexpanded
vs. normalprotected
, I'm no longer so sure that they're the same, or whether the ε-TeX definition is still relevant.– G. S.
31 mins ago
I did look through
syst-aux.mkiv
and found that line, but given David Carlisle's answer and the fact that I get different errors when I use unexpanded
vs. normalprotected
, I'm no longer so sure that they're the same, or whether the ε-TeX definition is still relevant.– G. S.
31 mins ago
add a comment |Â
G. S. is a new contributor. Be nice, and check out our Code of Conduct.
G. S. is a new contributor. Be nice, and check out our Code of Conduct.
G. S. is a new contributor. Be nice, and check out our Code of Conduct.
G. S. 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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f455101%2fwhat-is-the-difference-between-unexpanded-and-protected-in-context%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
2
unexpandeddef
is only used by ConTeXt, which has different namings.– egreg
6 hours ago
I probably should have mentioned in the original post that I'm working with ConTeXt, sorry.
– G. S.
57 mins ago