# What is the right space between a math operator and its subscript?

I am trying to define a command for a math operator \mathcal P_\mathrm{ext}. So I thought some candidates for this:

• \mathcal P_\mathrm{ext}(H)
• \operatorname{\mathcal P}_\mathrm{ext}(H)
• \DeclareMathOperator{\Pm}{\mathcal P} and \Pm_\mathrm{ext}(H)

There are some differences. I didn't expect the space between \mathcal P and the subscript when I use commands like \operatorname. I wonder what the right one is. Or should I put the subscript inside the \operatorname? (but it seems strange to use like that...)

Here is the MWE:

\documentclass{article}
\usepackage{amsmath, amssymb}
\DeclareMathOperator{\Pm}{\mathcal P}

\begin{document}
\begin{align*}
&\mathcal P_\mathrm{ext}(H) \\
&\operatorname{\mathcal P}_\mathrm{ext}(H) \\
&\Pm_\mathrm{ext}(H)
\end{align*}
\end{document}

• in all three cases the input syntax should be _{\mathrm{ext}} it is not a good idea to rely on the weird parsing rules that make _\mathrm{ext} appear to work. – David Carlisle Jul 9 '18 at 7:50

\documentclass[fleqn]{article}
\usepackage{amsmath, amssymb}
\DeclareMathOperator{\Pm}{\mathcal{P}}
\showoutput
\begin{document}
\begin{align*}
&\mathcal{P}_{\mathrm{ext}}(H) \\
&\operatorname{\mathcal P}_{\mathrm{ext}}(H) \\
&\Pm_{\mathrm{ext}}(H)\\
&\mathop{\mathcal{P}_{\mathrm{ext}}}(H)
\end{align*}

a $\log x$

a ${}\log x$

\end{document}


The specific example makes the answer a bit trickier than it would otherwise have been. I would say that the most logical markup would be \mathop{\mathcal{P}_{\mathrm{ext}}} as you want the subscripted term itself act as a \mathop.

However the reason that you see different spacing here is because you are on the right hand side of an alignment where implicitly the expression is prefixed by {} so you are getting a thin space from the \mathop to separate it from the (invisible) preceding term. So it is like the second \log example I added to the example here/ So why in the vast majority of cases the \mathop spacing for \log is the right thing the extra space here is probably not right and should be removed by \! or by using a form that does not give a \mathop, eg {\Pm}

• Thanks for the answer. Yes, I am using P_{ext} itself as the operator. What I am confused is the following: both \operatorname{P}_{\mathrm{ext}} and \operatorname{P_{ext}} should mean the operator P with the specific restriction ext (I am also using operators with other subscripts.) But they print different result. So what should be the convention that I use? – The Great Seo Jul 9 '18 at 8:33
• @TheGreatSeo if you just use operatorname around the P then you lose the font-specified kerning to bring the ext under the slope of the P, as you are no longer subscripting a simple character but a tex-constructed mathop tem – David Carlisle Jul 9 '18 at 8:37
• So I may always need to define an operator with more effort if there is a chance for it to have a subscript.. Thanks for the advice! – The Great Seo Jul 9 '18 at 15:07

If you use \operatorname{\mathcal{P}}_{\mathrm{ext}}, TeX cannot kern the subscript.

If you just need “ext” as subscript, you can define

\DeclareMathOperator{\Pme}{\mathcal{P}_{ext}}


If the subscript is variable,

\newcommand{\Pm}[1]{\operatorname{\mathcal{P}_{#1}}}


and call it as \Pm{ext}.

Full example:

\documentclass{article}
\usepackage{amsmath}

\DeclareMathOperator{\Pme}{\mathcal{P}_{ext}}

\newcommand{\Pm}[1]{\operatorname{\mathcal{P}_{#1}}}

\begin{document}

$\Pme(H)$

$\Pm{ext}(H)$

\end{document}


If you prefer the _ notation:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\NewDocumentCommand{\Pm}{e{_}}{%
\operatorname{\mathcal{P}\IfValueT{#1}{_{#1}}}%
}

\begin{document}

$\Pm_{ext}(H)$

\end{document}


Note that in any of the above case you just type in ext, because it will be typeset as part of \operatorname; \mathrm is not needed.

• Thanks for the various methods for the desired function, especially the last one! – The Great Seo Jul 9 '18 at 15:09