[Tex/LaTex] How to fix the spacing before starred commands from physics package

physicsspacing

\documentclass{article}
\usepackage{physics}
\begin{document}
    \fboxsep=0pt
    This is some \fbox{$\ev*{\hat{O}_P}$} and then some.
\end{document}

enter image description here

There seems to be extra spacing added before the left angle bracket as opposed to the space after the right angle bracket when using \ev*.
Is there anything I can do to fix it if I want to continue using this command from the physics package?

By fix, I mean I want the spacing of the right angle bracket on both sides.

Edit: I realized it does not happen with the non-starred version of the command, \ev{\hat{O}_P} gives the correct spacing on both sides. And that the problem seems to carry over to other starred commands like \ket*{x} and \bra*{x} where additional space is added to the left of the output.

Best Answer

I looked at the definition of \ev in the physics package. In your case it essentially reduces to

\vphantom{\hat{O}_P}\left\langle\smash{\hat{O}_P}\right\rangle

The \vphantom{\hat{O}_P} will insert a box of zero width and of type mathord, but when followed by a mathopen atom (which \left makes automatically), spacing is inserted.

The definition of \ev makes absolutely no sense. The implementers are trying to reverse the effect of the automatic scaling of \left and \right by using \smash to hide the height of the content, but then the construct will have no height and depth, so they reinserted using \vphantom.

The package code is also full of spurious spaces. Considering the quality of the implementation, the best way to fix this issue is by not using the physics package.

Related Question