Too small space when using \DeclareMathOperator

If \id denotes the identity map, then it shouldn't be an operator, but an ordinary symbol:

\newcommand{\id}{\mathrm{id}}

Notice also that \DeclareMathOperator* is meant for defining operators that take limits above and below them (such as \min and \max).

The behavior is easily explained: when we write \log -2 we want the - not to be treated as a binary operation symbol. For TeX your \id\circ g is just the same: if a Bin atom follows an Op atom, it is converted into an Ord atom. It's a mistake to define something with \DeclareMathOperator just to have upright letters.


The reason of the problem is a deficiency of TeX's spacing algorithm. Knuth made only one class for both operators and big operators where two would be needed (you want $\sum -a_i$ to have the minus behave like a unary operator, but that's not the case for $\ln + C$, the sum of \ln and C). The problem arises with all binary operators following an operator, e.g. in formulas like $\exp \circ g$, $\det \otimes \rho$, etc.

As you want \id to behave (in formulas like $\lambda \id + u$) like an operator on the left but not on the right (because, normally, when \id has an argument, the argument will always be in parenthesis, so there is no need for any additional spacing on the right), you can just define it to be of class \mathop{} on the left and of class \mathord on the right. This should solve all the spacing problems you encounter:

\newcommand{\id}{\mathop{}\mathopen{}\mathrm{id}}

A few tests:

examples of use of the \id command

For information, the nath package fixes this problem (see §11 of the documentation, page 7), but also does a lot of other stuff which you may not want.