# Combining \operatorname with \mathnormal and \mathrm

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:

On the other hand, if I write

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


then the numbers' font is changed:

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

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

-
Can you please explain why you want to use \operatorname, instead of just typing f_2^n? – Hendrik Vogt Oct 23 '12 at 14:11
Because of the spacing: E.g. a\f{2}{n}+b is different from a\f{2}{n}+b. – aulste Oct 24 '12 at 8:33
OK, that's true. I'm still not sure why you want that different spacing - that would be interesting to know. – Hendrik Vogt Oct 24 '12 at 8:54
The idea is simply to highlight function symbols in somewhat lengthy equations, such that it is easier to determine which symbols are functions, constants and so on. – aulste Oct 24 '12 at 9:24
Thanks for the info! (Let me mention that it might be OK to do this for educational purposes, but not in usual typesetting.) – Hendrik Vogt Oct 24 '12 at 10:00

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$


-
Thanks for your answer. I extended my question such that my problem should be quite clear now. – aulste Oct 23 '12 at 13:48
Your first suggestion puts the subscript 1 not close enough to the f, just like \operatorname{\mathnormal{f}}_{#1}^{#2}. The second one is, unfortunately, also not the desired solution as I don't want the operator to show limits. – aulste Oct 23 '12 at 13:54
it's not close because operatorname gives it mathop spacing which forces a gap, I updated my answer with a variant without that. – David Carlisle Oct 23 '12 at 14:11
Oh updated answer again. I think it's the 2nd form you want with the 1 still kerned back to the f and operator spacing for the whole constrruct – David Carlisle Oct 23 '12 at 14:16
Thanks. The second form solves my problem. \operatorname{foo} reduces to \mathop{\kern0pt \operator@font foo} where \operator@font caused my problem. For anyone who is interested in the details, I refer to tex.stackexchange.com/a/67956/7160 – aulste Oct 24 '12 at 9:14