# Reduce Space Between Characters in New Command

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?

-

## migrated from stackoverflow.comMay 28 '11 at 17:09

This question came from our site for professional and enthusiast programmers.

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)}}

-
And if you want something like $\ps{X}{\dfrac{1}{y}}^2$ to work correctly (the exponent 2 will be too low with your solution), you can by using \mathopen{}\mathclose{\left(#2\right)}. –  Philippe Goutet May 29 '11 at 8:46
@Philippe You can use \ps{X}{\dfrac{1}{y}\aftergroup^\aftergroup2} :) –  egreg May 29 '11 at 17:29
if you like \aftergroup trickery, you can use it to redefine \left and \right to produce open and close atoms (see tex.stackexchange.com/questions/2607/…). Here, it's really a shame that your macro \ps doesn't work correctly if there's an exponent afterwards when the fix is so simple. –  Philippe Goutet May 29 '11 at 21:51
@Philippe I don't think that the OP has the necessity to set exponents after the parenthesis. But I'll edit my answer anyway. Thanks. –  egreg May 29 '11 at 21:55
I knew posting to StackExchange.com was the right thing to do. I really appreciate all of the help. I'm definitely coming back here with any future questions. –  Max May 30 '11 at 0:10

You can use a math kerning with a negative value (change -3mu to the value that best suits your needs):

\newcommand{\ps}[2]{\mbox{P}_{#1}\mkern-3mu\left(#2\right)}

-
Thanks. I really appreciate it. –  Max May 28 '11 at 17:50
this will leave an unwanted space after the construction. Moreover it won't work in subscripts and superscripts (this would be solved with \nonscript\mskip-3mu, though). –  egreg May 28 '11 at 21:46
@egreg: thanks for the explanation. –  Gonzalo Medina May 28 '11 at 21:58
@Max: as @egreg has pointed out, my solution is not completely correct. You should accept egreg's answer instead of mine. –  Gonzalo Medina May 28 '11 at 21:59
I remembered a message by Will Robertson on comp.text.tex; he ascribed the method to F. Mittelbach. –  egreg May 28 '11 at 22:06

You can see how negative spacing commands are used on this page. So for your example, it would be something like

\newcommand{\ps}[2]{\mbox{P}_{#1}\!\left(#2\right)}

-
We prefer for answers on this site to be self contained rather than just links to other pages. Could you perhaps add to this answer some examples of how the OP might achieve the desired results? –  Seamus May 28 '11 at 17:17
@ Seamus: Uhm, I did actually put an example but maybe I am missing the point, care to correct me please? –  percusse May 28 '11 at 17:25