It's not clear exactly what layout you want, (perhaps a full minimal example and image in your question would have helped).
The main function of \operatorname
is to provide multi-letter operators like log etc, if you want a math italic f it seems that you just need one of these, depending on where you want the limits to go.
The other function is to give it operator spacing, ie a small gap before the argument, so perhaps the first or second form is what you are looking for?
$ f_1^2 x $
$ \mathop{f_1^2} x $
$ \mathop{{}f}_1^2 x $
$ \mathop{{}f}\limits_1^2 x $
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:
\DeclareRobustCommand{\operatorname}{%
\@ifstar{\qopname\newmcodes@ m}%
{\qopname\newmcodes@ o}}%
\DeclareRobustCommand{\qopname}[3]{%
\mathop{#1\kern\z@\operator@font#3}%
\csname n#2limits@\endcsname}
\newcommand{\DeclareMathOperator}{%
\@ifstar{\@declmathop m}{\@declmathop o}}
\long\def\@declmathop#1#2#3{%
\@ifdefinable{#2}{%
\DeclareRobustCommand{#2}{\qopname\newmcodes@#1{#3}}}}
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:
\DeclareMathOperator{\xyz}{xyz}
\DeclareMathOperator*{\XYZ}{XYZ}
are pretty much equivalent to saying
\DeclareRobustCommand{\xyz}{\operatorname{xyz}}
\DeclareRobustCommand{\XYZ}{\operatorname*{XYZ}}
(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}
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);
\kern\z@
inserts an invisible object so that the entire contents of \mathop
will never be a single character (see https://tex.stackexchange.com/a/41267/4427 for details);
\operator@fonts
chooses the predefined font for math operators, which usually is the upright text font;
\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
\mathop{\mathrm{abc-def}}
will be rather different from
\operatorname{abc-def}
and the latter is usually expected. In some rare cases \mathop
is useful by itself:
\newcommand{\diff}{\mathop{}\!d}
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
\newcommand{\diff}{\mathop{}\!\mathrm{d}}
Also \stackrel
and the better amsmath
commands \overset
and \underset
are defined with an internal \mathop{...}\limits
but wrapped up in some other construction.
Best Answer
It's a tough call, for this case.
In the linked question, the symbol “id” was apparently used in the context of functors, so like
and, as shown there, declaring it as an operator would not work.
One is unlikely to use
\id x
for “the identity applied at x”, and\id(x)
will print just right.There is still a problem: if one has to type
r\id\otimes f
(r is supposed to be a scalar) then probablywould be a better choice, because a thin space would be added between r and
\id
, but the operator nature on the right is nullified by adding a negative thin space and an empty ordinary atom. Unfortunately, there's little hope to have a context aware\id
that would work also on the right and, for “id r” (meaning right multiplication) you need to resort to\id\,r
.Other function symbols like
\sin
and so on don't usually suffer from the issue.