Sign up ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

One sees all kind of versions in source files for defining something like a limit etc. So my question is which one serves what purpose. Is there any "best practice" in chosing one over the other?

share|improve this question
Related: How do I do a one-shot MathOperator? – Lover of Structure Jul 4 '13 at 21:53

3 Answers 3

up vote 56 down vote accepted

When is it better to use \operatorname (or its wrapper \DeclareMathOperator) instead of \mathop? The answer is easy: always, unless you know precisely what's the behavior of \mathop.

First of all, one must of course recall that \operatorname and \DeclareMathOperator are provided by the amsopn package, which is automatically loaded by amsmath, but is also available standalone.

Let's see the main definitions:

  \@ifstar{\qopname\newmcodes@ m}%
          {\qopname\newmcodes@ o}}%
  \csname n#2limits@\endcsname}
  \@ifstar{\@declmathop m}{\@declmathop o}}

The command \qopname is not really meant to be used in a document; the purpose of its first argument is to add some declarations such as \newmcodes@ before typesetting the operator name.

The \operatorname and \DeclareMathOperator each have a *-variant that passes to \qopname a second argument m instead of o. The latter command is just a wrapper:


are pretty much equivalent to saying


(but treated more efficiently) so what we need to examine is just \operatorname.

A call of \operatorname{xyz} translates into

\qopname\newmcodes@ o {xyz}

which becomes

  \mathop{\newmcodes@\kern\z@\operator@font xyz}\csname nolimits@\endcsname}
  1. The \newmcodes@ declaration takes care that some characters are treated differently as usual in math formulas (in particular the hyphen doesn't become a minus sign);

  2. \kern\z@ inserts an invisible object so that the entire contents of \mathop will never be a single character (see for details);

  3. \operator@fonts chooses the predefined font for math operators, which usually is the upright text font;

  4. \nolimits@ is just an alias for \nolimits, so following subscripts and superscripts won't be typeset above and below the operator, unless countermanded by a \limits declaration.

For \operatorname* it's exactly the same, with the only difference that \nmlimits@ will be executed instead of \nolimits@. This macro is defined to be equivalent to \displaylimits, which makes the operator behave like the standard \lim or \min.

If an operator is used just a couple of times in a document, one can maybe dispense with defining a command with \DeclareMathOperator; but readability of the source is, in my opinion, enhanced if proper names for logical structures are used.

For \mathop one has to remember that it doesn't choose any particular font and it doesn't correct some glitches: so the output of


will be rather different from


and the latter is usually expected. In some rare cases \mathop is useful by itself:


is an example, where the empty \mathop is used to provide the correct spacing before the "d". Note that if one really wants to have an upright "d", it would be incorrect to define it as \operatorname{d} and the same as before with \mathrm{d} instead of d should be used: explicitly, the alternative is


Also \stackrel and the better amsmath commands \overset and \underset are defined with an internal \mathop{...}\limits but wrapped up in some other construction.

share|improve this answer
Why do you use \mathop{} to affect spacing, if you then get rid of the extra space provided with \!? Wouldn’t it be better to use just a single spacing modifier? – Daniel H Sep 22 at 20:06
@DanielH With \mathop there are two thin spaces: one before and one after. The \! gets rid of the latter, but the former remains. – egreg Sep 22 at 20:07
I figured that was part of it, but why not just use \, instead, which also has the total effect of a single thin space? – Daniel H Sep 22 at 20:08
@DanielH The thin space is not wanted if you say $\diff x$ or, more probably, \frac{\diff f}{\diff x}. Of course \int f(x)\,dx is shorter than \int f(x)\diff x; but when you have 100 integrals and 200 Leibniz derivatives in your document and your supervisor tells you that the “d” of the differential must be upright… – egreg Sep 22 at 20:15
You’re right, of course. I’d found this page while thinking about integration only and got confused. – Daniel H Sep 22 at 21:29

\mathop is the most primitive command, declaring the class of a character or subformula to be a unary math operator like \sum, for instance. This has consequences for spacing, compared to binary operators declared with \mathbin or binary relations declared with \mathrel, for instance.

Most math operators are written out as textual names. Some definitions from latex.ltx:

\def\max{\mathop{\operator@font max}}
\def\min{\mathop{\operator@font min}}
\def\sup{\mathop{\operator@font sup}}
\def\inf{\mathop{\operator@font inf}}
\def\arg{\mathop{\operator@font arg}\nolimits}
\def\ker{\mathop{\operator@font ker}\nolimits}
\def\dim{\mathop{\operator@font dim}\nolimits}
\def\hom{\mathop{\operator@font hom}\nolimits}

You see that a special font \operator@font is used; furthermore, one can see that an operator declared with \mathop is usually typeset with limits, that is, super- and subscripts are placed in a special position in displaymode. This can be turned off with \nolimits.

\operatorname from the AMSTeX bundle encapsulates this as a user command:

  \@ifstar{\qopname\newmcodes@ m}%
          {\qopname\newmcodes@ o}}%
  \csname n#2limits@\endcsname}

This basically means that \operatorname{dual} will typeset a math operator "dual" which looks like \max (i.e. with limits) and \operatorname*{dual} will typeset a math operator "dual" which looks like \arg (i.e. without limits).

\DeclareMathOperator is the corresponding declaration, i.e. \DeclareMathOperator\dual{dual} creates a new macro \dual which works like \max.

On usage:

  • With \mathop, anything can be declared a math operator, i.e. if you want to use * like a prefix operator (with limits), you can just say \mathop{*}.
  • \DeclareMathOperator should be used if you want to define a new operator like \max.
  • \operatorname should be used for special cases where you need a special operator name only once.
share|improve this answer

\mathop is a plainTeX command, which declares a big operator like


DeclareMathOperator is from AmsMath's amsopn subpackage, called as:


whereas operatorname is kind of an operator "on-the-fly". Input of


has the same meaning as \Res defined with mathop or DeclareMathOperator

I think, if you loaded AmSMath (always a good idea) then I would use DeclareMathOperator and operatorame in cases this operator is seldom used in the file or to make some text in math-mode upright and with space-padding.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.