9

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?

  • 2
    It depends on the chosen fonts. A good combination of text and math fonts should use the same punctuation symbols in both math and text. If you use a bad combination, then you will see a difference. Personally I write $x$.. BTW: unless you are using plain TeX, you should not be using $$...$$ syntax as it does not follow the general LaTeX configuration. – daleif Nov 25 '14 at 9:26
  • 1
    Note that you should use \[..\] in LaTeX rather than $$..$$. Ideally you should do $x$, and then you would need \[x\text{,}\] but since in Computer Modern they look almost (if not completely) identical, people tend to use \[x,\] which is, usually, not noticeable. – Manuel Nov 25 '14 at 9:27
  • Thanks!! What is the difference between [..] and $$..$$? I do not understand that "you should not be using $$...$$ syntax as it does not follow the general LaTeX configuration". – Zuriel Nov 25 '14 at 9:41
  • @Zuriel - Please see the posting Why is \[ ... \] preferable to $$ ... $$? – Mico Nov 25 '14 at 10:06
12

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.

7
\documentclass{article}



\begin{document}

\showoutput
$,$,

\end{document}

produces

enter image description here

which are "quite similar" in the default computer modern fonts, but if you look at the log you see

....\mathon
....\OML/cmm/m/it/10 ;
....\mathoff
....\OT1/cmr/m/n/10 ,

So the second one is a , in cmr10 whereas the first is a ; in cmmi10 (classic TeX encodings are weird :-) the extent to which they look the same (or in fact are the same using copies of the same font paths internally) is a choice of the font designer.

4

As noted in the comments one should use matching text and math fonts which use very simmilar punctuation symbols.

According to the TeXbook using Test with variable $x$. is to be preferred as well as Test with one $x$, two $y$, or three variables $z$. mainly because in several cases the punctuation symbols are more tightly spaced in math mode than in text.

Concerning Displayed math you are on the safe side if you use By the formula\[x=y+z \hbox{,}\]we have (again according to the TeXbook) or By the formula\[x=y+z \text{,}\]we have (which should be preferred when using amsmath). Both will result in the , being printed in text font.

BTW: Concerning $$x+y$$ vs. \[x+y\] for displayed math have a look at this or this Answer

  • In a LaTeX document, it's good practice to use \mbox instead of the Plain-TeX \hbox directive. (The instruction \mbox is defined in the LaTeX kernel as follows: \long\def\mbox#1{\leavevmode\hbox{#1}}. The additional \leavevmode instruction tends to guard against some unexpected typographic surprises...) However, as you take care to point out as well, it's even better practice to use the \text macro if the amsmath package is loaded. – Mico Nov 25 '14 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.