The answer to this question explains how to add space around inline equations, but it doesn't account for punctuation. You can see what I mean in the picture below.
Is there a way to put the space after the comma, rather than before it? The obvious solution of putting the comma inside the equation environment, e.g., $A = \pi r^2,$
won't work because the fonts are different (I'm using XeLaTeX). That is, unless you manually specify each time that the comma should be a different font, but I'm hoping for a lazier solution (which accounts for all of the normal punctuation: periods, commas, semicolons, etc.).
Best Answer
If you use a non zero value for
\mathsurround
, you should add punctuation inside the formula and then restore the spacefactor afterwards.Here the settings are exaggerated by the high
\xspaceskip
, used just for testing that the additional space is inserted when appropriate (fourth paragraph).Here's the output of
when
\mathsurround=3pt
is used: