[Tex/LaTex] Reduce Space Between Characters in New Command

macrosspacingtypography

I'm not satisfied with the new command I've made. My code:

\newcommand{\ps}[2]{\mbox{P}_{#1}\left(#2\right)}
$\ps{Y}{y}$ %example

My problem is that there's too much space between the subscripted Y and the left parenthesis. Does anyone know how to get these two closer together?

Best Answer

A \left-\right subformula is treated as an Inner atom and this adds some space before and after the subformula, in certain circumstances. One can get the desired behavior by

\usepackage{amsmath}
\newcommand{\ps}[2]{\operatorname{P}_{#1}
  \mathopen{}\left(#2\right)\mathclose{}}

so the spacing inserted will disappear (TeX doesn't insert space between an opening atom and an inner one, nor between an inner atom and a closing one).

It's better to define "P" with \operatorname than with \mbox.

As Philippe Goutet remarks, if superscripts or subscripts need to be attached to the closing parenthesis, the definition should be

\newcommand{\ps}[2]{\operatorname{P}_{#1}
  \mathopen{}\mathclose{\left(#2\right)}}