What is the difference between \unexpanded and \protected in ConTeXt?

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.


If I compile with context the following

\show\unexpanded

I get

> \unexpanded=\protected

tex error       > tex error on line 1 in file /Users/enrico2013/provaccia/sep2018/tttsssttt.tex: ?

l.1 \show\unexpanded


1 >>  \show\unexpanded
2     

In /usr/local/texlive/2018/texmf-dist/tex/context/base/mkiv/syst-aux.mkiv, line 61 reads

\let\unexpanded\normalprotected

If I add \show\normalprotected, 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).