[Tex/LaTex] What does LaTeX understand as an operator

math-mode

I haven't really got how does LaTeX understand the objects created through \operatorname{…}/\DeclareMathOperator. I know that it typesets them in upright roman, but how the system treats it?

When should I use those commands in order that LaTeX treats that functions as operators.

  1. $d(x,y)$
  2. $\operatorname{d}(x,y)$
  3. $\mathit{Var}(x)$
  4. $\operatorname{Var}(x)$
  5. $P(X=x)$
  6. $\operatorname{P}(X=x)$
  7. $E[X]$
  8. $\operatorname{E}[X]$
  9. $\mathit{Bin}(n,p)$
  10. $\operatorname{Bin}(n,p)$
  11. $B(\ell,\varepsilon)$
  12. $\operatorname{B}(\ell,\varepsilon)$
  13. $O(x)$
  14. $\operatorname{O}(x)$
  15. \sigma = \mathit{id}
  16. \sigma = \operatorname{id}

d(x,y) means the distance, Var the variance of a distribution, P the probability, E the average (or mean of a distribution), Bin the binomial distribution, B the ball with center l and radius epsilon, O the Big O notation.

In those examples, which ones should be treated by LaTeX as operators? And then be typeset upright.

May be my problem is that I don't really understand what an operator is (apart from it's meaning in LaTeX).

EDIT: well, as @cgnieder says, this can be off topic. The problem, why I thought this wasn't off topic is that I've never thought about operators and upright roman out of the LaTeX world. Basically because I don't change the shape when I handwrite math. Therefore, I do think this is (La)TeX related. Sorry for editing instead of adding a comment, but my connection doesn't allow me to do so.

EDIT2: I didn't want to include the differential operator in the list, as it has its own question.

Best Answer

Mathematically an operator (in this context) is a function used in standard prefix form as opposed to a binary operator such as + that comes between its arguments (or a postfix operator beloved of group theorists that comes after its arguments).

To TeX an operator is any expression that (after expansion) has been surrounded by the \mathop{...} primitive, or is a character token or \mathchardef-ed token of math class 1 (large operator).

So to get mathematically meaningful typesetting the idea is to make these two notions match up as well as possible.

Although there are a few wrinkles, notably that a single-letter primitive mathop is vertically centred on the math axis which usually works out OK for symbols in display mode, but often isn't needed for alphabetic operators such as d or D especially in inline math, so sometimes you need to use \mathord rather than \mathop for those, or ensure the mathop atom never just has a single letter by including {} as in \mathop{d{}} (This is what the AMS \DeclareMathOperator does). It's also conventional to use a Roman font for multi-letter operator names, although TeX itself doesn't consider the font choice to be part of the mathop specification, the default font for \mathop is the same as that in the rest of the expression.

The spacing given to an atom depends on its class (ordinary or mathop in the current case) but also on the class of the following atom. Your question has a lot of examples, just picking the Bin one, you don't really see the effect of mathop spacing when it is followed by ( as that has \mathopen class however if you follow it by a mathord character such as X then you will see the difference more clearly.

\documentclass{article}

\usepackage{amsmath}

\begin{document}

$\mathit{Bin}(n,p)$

$\operatorname{Bin}(n,p)$

$\mathrm{Bin}(n,p)$

$\mathop{\mathrm{Bin}}(n,p)$

$\mathrm{Bin} X$

$\mathop{\mathrm{Bin}} X$

\end{document}

enter image description here