According to this answer \protect\foo expands to something like \noexpand\protect\noexpand\foo when it gets saved to a macro (e.g. in a context like a beamer frame). I think \protected\def basically just places \protect in front of every instance of the macro. If not, what does it do? If so why does \expandafter in a protected macro applied to an argument work correctly?
The rest is just provided for clarification. I'm trying to understand what \protected does and felt the example might help explain what I'm asking.
For instance, the command defined below works fine even in beamer frames but if I think about what happens if I replaced \Tdeg{\zeron{5}} with \noexpand\protect\noexpand\Tdeg{\zeron{5}} wouldn't the result be to expand the argument \zeron{5} before it caught by the \expandafter in \Tdeg? If so why does this still work (i.e. output A not B) when I run it inside a beamer frame?
\def\zeron#1{0^{#1}}
\def\first@pmg@rdmxs(#1#2){#1}
\protected\def\Tdeg#1{\ifthenelse{
\equal{\string \zeron }{\expandafter\string \first@pmg@rdmxs(#1)}
{A}
{B}}
If that isn't clear enough from the post just delete the post as I've failed to communicate utterly as the only point of the code was to illustrate how one might incorrectly reason about \protected.
– Peter Gerdes Oct 28 '21 at 17:57\protectnot\protecteddeal with arguments at all. as you say if you use\protect\Tdeg{\zeron{5}}in an expansion context, the expansion of\Tdegwill be suppressed but\zeron{5}will expand. But you haven't shown any\Tdegbeing used in such a context (or any context) – David Carlisle Oct 28 '21 at 18:19