# Too small space when using \DeclareMathOperator

Currenlty I'm writing a math script (ring theory, PDF). When I need a new math operator I use \DeclareMathOperator from the amsopn-package. However I noticed some strange behaviour when using an operation with \circ. Example:

\listfiles
\documentclass[draft]{minimal}
\usepackage{amsopn}
\DeclareMathOperator*{\id}{id}
\begin{document}
$\id\circ g$

$h\circ g$
\end{document}


In the first version the g is very close at the \circ whereas the second version seems normal. This spacing issue only happens when I use \DeclareMathOperator. Is this problem known to you? What can I do to prevent it?

The file list:

minimal.cls    2001/05/25 Standard LaTeX minimal class
amsopn.sty    1999/12/14 v2.01 operator names
amsgen.sty    1999/11/30 v2.0

-
when two operators are together, the spacing changes to what you see here. you can negate the "operatorness" of \id by enclosing it in braces -- {\id}. this won't change its behavior if you do apply limits (within the braces), but it will affect the spacing relative to what comes next. –  barbara beeton Apr 26 '11 at 12:27

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.

-
In my case \id can take limits. So I assume this is correct. However the spacing issue remains for both versions. –  qbi Apr 26 '11 at 11:01
Did you try your \id_{A} in a displayed formula? :) From what I see in your text, you need only subscripts and the definition I proposed is what you are looking for. –  egreg Apr 26 '11 at 11:06
The problem will show up with any binary relation rather than \circ: for example $\id+g$. As pointed out in the answer, the fix is to have an \id of type ordinary, so, for example $\mathord{\id}\circ g$, assuming you insist on declaring it as an operator in the first place. –  jfbu Apr 26 '11 at 12:27
I'm sorry. I misinterpreted your answer. Your solution is absolutely perfect. ;-) –  qbi Apr 26 '11 at 13:52

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:

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.

-
About mixing math character classes, we now have this answer to my question Mixing math character classes (e.g. \mathord to the left and \mathrel to the right). –  Lover of Structure Dec 18 '13 at 15:38