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:

$\id\circ g$

$h\circ g$

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
  • 3
    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. Commented Apr 26, 2011 at 12:27

2 Answers 2


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


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
    Commented Apr 26, 2011 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
    Commented Apr 26, 2011 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.
    – user4686
    Commented Apr 26, 2011 at 12:27
  • I'm sorry. I misinterpreted your answer. Your solution is absolutely perfect. ;-)
    – qbi
    Commented Apr 26, 2011 at 13:52
  • i thought \DeclareMathOperator was exactly for the functions with upright letters, like sin, cos and id. apparently i am wrong. what are math operators then?
    – peter
    Commented May 9, 2021 at 13:18

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:


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.

  • 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). Commented Dec 18, 2013 at 15:38
  • \newcommand{\id}{\mathop{}\mathopen{}\mathrm{\id}} should read \newcommand{\id}{\mathop{}\mathopen{}\mathrm{id}} without the backslash in the last {id}. Commented Apr 17, 2016 at 17:15
  • Dear Philippe, in your very useful document here, you rather defined \newcommand{\Id}{\mathop{\mathrm{Id}}\mathopen{}\mathord{}}. Is it completely equivalent to what you wrote? If not, what are the differences? (I believe that \mathord{} does not add any space, but I am confused about the order of appearance of the commands).
    – Watson
    Commented Jan 8, 2021 at 17:37
  • 1
    @Watson: yes, it is totally equivalent. The important point is to have a \mathop on the left, a \mathord on the right and a \mathopen in the middle to prevent a spurious space between the two. You could also write \mathop{}\mathopen{\mathrm{id}}\mathord{} it would be equivalent. You can also replace \mathord{} by {} as \mathord is the default spacing class. The best way to understand all this is to set up a few varied examples and modify the definition so see the effects. Commented Jan 9, 2021 at 5:51
  • i think having the actual displayed object (here \mathrm{id}) at the very right is correct. if you end on {}, this might screw with subscript and superscript positioning, at least in general. in this case where you only have regular letters, it might be the same.
    – peter
    Commented May 9, 2021 at 13:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .