# space between W (math-mode) and comma

I have this simple LaTeX document:

\documentclass{article}

\begin{document}
There is quite a lot of space after a math-mode $W$, if it is followed by a comma.
\end{document}


To me, this looks like too much space after the W. Is there any solution to that? I'd prefer a global fix.

• The fastet solution is to manually add some negative kerning, e.g., $W$\kern-.3em, Jun 6 '17 at 11:46
• Insert more words after it and see if the space changes. I'd keep the default behaviour, ie, lets TeX decides to you the space to be used. Jun 6 '17 at 11:46
• The space shows the comma is not part of the formula. Jun 6 '17 at 11:53
• @egreg That's a nice explanation, but does $A$,show that the comma is part of the formula? ;^) That is, $W$, versus $A$, then W, and A, shows consistent kerning between text and mathmode, even as A and W are kerned differently. Jun 6 '17 at 12:03
• @egreg OK, but I don't have a full formula, I have a single character in math mode. Do you have any suggestion how to solve this issue? Jun 6 '17 at 12:05

You could (1) Just leave it or (2) Add some arbitrary negative space or (3) Set the comma inside the math allowing the font specified correction to be applied, but relying on a font setup that makes the math comma visually close enough to the text comma or (4) Use the text comma, but insert a kern equal to the spacing correction that would have been applied had the comma been in math mode.

I'd probably do (1) :-)

\documentclass[a4paper]{article}
\showoutput
\parindent0pt

\newcommand\mykern[2]{%
\sbox0{$#1#2$}\sbox2{$#1\hbox{}#2$}%
\kern\dimexpr\wd0-\wd2\relax
#2}

\begin{document}

There is quite a lot of space after a math-mode $W$, if it is followed by a comma.

There is quite a lot of space after a math-mode $W\!$, if it is followed by a comma.

There is quite a lot of space after a math-mode $W,$ if it is followed by a comma.

There is quite a lot of space after a math-mode $W$\mykern{W}{,} if it is followed by a comma.

\end{document}