What is the difference between unexpanded and protected in ConTeXt?

The name of the pictureThe name of the pictureThe name of the pictureClash 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 (for edef, xdef, message, errmessage, special, mark, marks or when writing the token list for write to a file) or when looking ahead in an alignment for noalign or omit.



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?










share|improve this question









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














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 (for edef, xdef, message, errmessage, special, mark, marks or when writing the token list for write to a file) or when looking ahead in an alignment for noalign or omit.



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?










share|improve this question









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












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 (for edef, xdef, message, errmessage, special, mark, marks or when writing the token list for write to a file) or when looking ahead in an alignment for noalign or omit.



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?










share|improve this question









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 (for edef, xdef, message, errmessage, special, mark, marks or when writing the token list for write to a file) or when looking ahead in an alignment for noalign or omit.



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






share|improve this question









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.











share|improve this question









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.









share|improve this question




share|improve this question








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












  • 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










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.






share|improve this answer






















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










  • 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











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

















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






share|improve this answer




















  • 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











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: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






G. S. is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















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






























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.






share|improve this answer






















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










  • 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











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














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.






share|improve this answer






















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










  • 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











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












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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








edited 1 min ago

























answered 6 hours ago









David Carlisle

471k3811001829




471k3811001829











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










  • 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











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










  • 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










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










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






share|improve this answer




















  • 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















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






share|improve this answer




















  • 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













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






share|improve this answer












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







share|improve this answer












share|improve this answer



share|improve this answer










answered 35 mins ago









egreg

689k8518333082




689k8518333082











  • 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
















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











G. S. is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















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.













 


draft saved


draft discarded














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













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

List of Gilmore Girls characters

Confectionery