17

I found there to be very odd spacing when using a math macro just before a binary operation. Here is a minimal example:

\documentclass[11pt]{article}
\usepackage{amsmath}
\DeclareMathOperator{\id}{id}
\begin{document}

$x\otimes \id$

$\id \otimes x$

\end{document}

produces

enter image description here

I am aware that sometimes a macro "eats up" the space after it, requiring that we put it in braces or put a \ after it, but I wouldn't have expected the space after the operation to be what is affected. Can someone explain what is going on, and how I could set this up differently so that the spacing will turn out correctly?

1

2 Answers 2

16

Those are TeX's rules. You're defining \id as an Op atom (math operator), whereas \otimes is a Bin (binary operation) and x is an Ord (ordinary symbol). Thus $\id\otimes x$ would be interpreted as

Op Bin Ord

but this is not accepted by the rules, so the Bin atom is changed into a Ord (think to $\sin -x$, which is not what is usually printed, but would be surely wrong if it was "sine minus x").

Therefore the final sequence of math atoms is

Op Ord Ord

and the spaces inserted are

Op (thin space) Ord (no space) Ord

If your \id macro is for denoting the identity map, it shouldn't be a math operator, but an ordinary symbol:

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

In this way $\id\otimes x$ would be

Ord (medium space) Bin (medium space) Ord

3
  • Thank you for your answer, it's very helpful. But, I'm still unclear on why \id shouldn't be considered similarly to \sin - they are both special functions we want to give unitalicized names to, and I'm not sure what I'd do with one that I wouldn't do with the other. Could you explain (or link to an explanation of) the different ways of putting upright text in math mode, and when we should use each? Nov 6, 2012 at 22:48
  • Since you won't be writing $\id x=x$ but rather $\id(x)=x$, there's no point in defining it as a math operator. Function symbols such as \sin and \log are frequently used in combinations like \log\sin x where a thin space is needed, while your identity probably isn't used like this.
    – egreg
    Nov 6, 2012 at 22:54
  • Ah, I understand. I've always preferred putting parentheses even for things like \sin and \log, to avoid ambiguity, which is probably why I never noticed. Nov 6, 2012 at 23:02
6

For correct spacing around \otimes - a binary operator, I would make sure that the operator \id resembles an ordinal symbol by wrapping it inside a group {}:

enter image description here

\documentclass[11pt]{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\DeclareMathOperator{\id}{id}
\begin{document}

$x \otimes {\id}$

${\id} \otimes x$

\end{document}

You must log in to answer this question.

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