[Tex/LaTex] Does the comma look the same within/without the dollar signs

math-modepunctuation

In math mode when I type a sentence, my habit was to put commas/full stops/semicolons, etc. outside the dollar sign. For example, I would write Let the variable be denoted by $x$., instead of Let the variable be denoted by $x.$

But sometimes I need to place a formula in the centre by using double dollar sign and there is a problem. If I write By the formula $$e^{i\pi}+1=0$$, we have ..., then the comma will appear at the beginning the next line, which looks awkward. So I have to write By the formula $$e^{i\pi}+1=0,$$ we have ... instead.

My question is, do $x$, and $x,$ look exactly the same? If no, what should one do if s/he uses double dollar sign to centralize an expression but still prefers to place the comma outside of the dollar sign?

Best Answer

Under the normal setting, the math code for comma is "613B as it results from

\mathcode`\,="613B

in Plain TeX and

\DeclareMathSymbol{,}{\mathpunct}{letters}{"3B}

in LaTeX (precisely in fontmath.ltx). This means that the comma is a punctuation symbol (class 6), and that it's taken from the font specialized for math letters (family 1, where the math italic letters are the main object).

The glyph's shape therefore depends on how the fonts are designed: there may be a difference, particularly if the text and math font don't match (which would be a typographical error anyway). Why is the symbol “different”? Let's look with the standard setting:

\documentclass{article}
\begin{document}
\fboxsep=0pt \fboxrule=0.1pt % no padding, hairline box

\fbox{,} \fbox{$,$}

\makebox[0pt][l]{\fbox{,}}\fbox{$,$}

\end{document}

enter image description here

Looking at the first line seems to hint that the result is identica, which is confirmed by the second line.

However, a difference can be seen if NewTX is loaded; the same input as before, with the addition of \usepackage{newtxtext,newtxmath} produces

enter image description here

where we see that the math comma has no left sidebearing. Design decision.