[Tex/LaTex] Combining \operatorname with \mathnormal and \mathrm

math-modemath-operatorssubscriptssuperscripts

Related Question:
Typesetting the square of a mathematical operator

\operatorname converts its argument into a function symbol with appropriate spaces on the left and on the right. However, I often need sub- and superscripts applied on those symbols. So I'd like to define something like

\documentclass{article}

\usepackage{amsmath,amssymb}

\newcommand\f[2]{
    \operatorname{\mathnormal{f}_{\mathnormal{#1}}^{\mathnormal{#2}}}
}

\begin{document}
\begin{equation*}
  \f{2}{n}
\end{equation*}
\end{document}

Note that \operatorname{\mathnormal{f}}_{#1}^{#2} (sub- and superscript outside \operatorname) would place the subscript too far away from the letter f.

Here the problem begins: Since \operatorname internally applies \mathrm to its argument, \f{2}{n} typesets the exponent n upright:

error1

On the other hand, if I write

\newcommand\f[2]{
    \operatorname{\mathnormal{f}_{\mathnormal{#1}}^{\mathnormal{#2}}}
}

then the numbers' font is changed:

error2

This gets really tricky when combining letters (or other operators) and numbers like \f{2mn\cdot x}{\frac{c}{2}}:

error3

Is there a way to get the "right" letters and the "right" numbers at the same time?
That is:
desired

Best Answer

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 $

enter image description here

Related Question