When posting snippets of latex code that define or modify commands containing @, one commonly includes the
\makeatother wrapper that's necessary if pasting the snippet into an ordinary document. However, such pasting then has bad effects if it happens to occur somewhere that
\makeatletter is already in effect. Is there a good way to "save the state of 'at'", execute some code, and then restore the original state, whatever it might have been?
(Yes, I know that
\makeatother are local to groups. However, certain code doesn't work the same way inside a group, e.g. macro definitions are local to the group by default, so it would be better to avoid having to enclose the whole snippet in a group.)