Actually, most control sequences do not function as an implicit group; you have simply been lucky with your choice of superscripts. \textrm
is a font macro, and has been carefully designed as such to work without braces in a superscript for just this purpose. If you were to define your own macro
\newcommand*\timestwo[1]{2*#1}
you would find that $g^\timestwo{x}$
would be accepted, but produce the equivalent of ${g^2} * 2$
. This is because TeX will expand "arguments" to an exponent ^
but then take the first group (more or less) for the actual text of the exponent. (Hence, \textrm
works by expanding in such a way as to make a group around its argument the first thing that ^
eventually sees.)
Something similar happens with \mod
, which in fact expects an argument: writing \show\mod
at the command line would say
\mod=\long macro:
#1->\allowbreak \if@display \mkern 18mu \else \mkern 12mu\fi {\operator@font mod}\,\,#1.
That is, you're supposed to use it as \mod n
. In fact, this one will give you an additional error because the first typesettable material seen by ^
is the \mkern
, and since it's not expandable it both a) does not absorb its "argument" (either 18mu
or 12mu
depending on context) and b) is taken on its own as an exponent. And the expression \mkern
without an argument is invalid.
If you just want the upright-typeset operator called "mod", you can \DeclareMathOperator{\Mod}{mod}
and that will be usable in a superscript, because it is a single token taking no arguments.