23

If I want to list three constants a, b, c, it appears that both lines in the following MWE produce the same visual results, at least in the MWE itself and in all the experiments I have conducted:

\documentclass{article}

\begin{document}
$a,\ b$, and $c$

$a$, $b$, and $c$
\end{document}

However, is one more correct than the other? Can it cause issues to use the first one? I know that TeX is at least allowed to break the line at \, unlike in the case where I had just used a simple comma.

(I know I should probably insert a ~ before $c$, but I found that would distract attention from the real question here.)

  • 28
    By all means, used the second method: The fact that the "words" in the sentence fragment are single-letter variable names doesn't obviate the issue that, syntactically speaking, you're dealing with a sentence. Hence, TeX should be in text mode rather than in math mode to determine the "correct" amount of interword spacing. (By the way, I'm not alone in holding this view: The TeXbook itself also recommends the second method.) – Mico May 19 '15 at 8:45
  • The TeXbook covers this issue? Can you be more specific where? – Gaussler May 19 '15 at 8:53
  • 9
    Check out Chapter 18, "Fine Points of Mathematics Typing," and especially (on p. 161) "1. Punctuation". DEK wrote towards the bottom of that page: "... when typing formulas in the text of a paragraph, keep the math properly segregated: ... [I]f a comma or period or other punctuation mark [Mico adds: or space] belongs linguistically to the sentence rather than to the formula, leave it outside the $'s." – Mico May 19 '15 at 10:00
35

Yes it matters. In the first case the comma is from the math font, and depending on your math setup can be different from the text font. So you should make sure that all commas are either from text or math and not mixed. Which one is better depends on the context, in a normal sentence I would use the text comma.

\documentclass{article}
\usepackage{newtxmath} %to change the math fonts
\usepackage{amsmath}
\begin{document}
$a,\ b$, and $c$

$a$, $b$, and $c$

$a, b, \text{ and } c$
\end{document}

enter image description here

  • 1
    Very good observation! I've always used the correct method (only because I'm a stickler for semantics), but I've never noticed the effects of different font selection :) – Sean Allred May 19 '15 at 11:45
24

TeX will not break a line at the “control space”, because it's allowed to break lines in formulas only after binary operators such as + or =. Glue in math mode is not an allowed break point.

The spaces in

$a,\ b$, and $c$

will be different, because TeX adds a thin space between a punctuation atom (the comma) and an ordinary atom (the ‘b’), independently of any explicit intervening glue (or penalty).

So the “correct” way should be

$a$,~$b$, and~$c$

The three variables are just names, from a grammatical point of view, so this is no different from

Moe, Larry, and~Curly

Whether you should use the Oxford comma or not is up to your personal preference (I wouldn't).

Why no tie between Moe, and Larry, but one between $a$, and $b$? Because single variables in a text are much less prominent than a multiletter word, so it's better to help TeX in not letting it add a line break there.

I generally recommend to liberally use ~, so maybe

Moe,~Larry, and~Curly

would be even better. If TeX is not able to correctly break the paragraph, we can decide whether to remove a tie.

What about “for i=1,2,...,n” (that I wrote in obviously wrong way here)? The list of numbers forms a syntactical unit, so it should be

for~$i=1,2,\dots,n$

Such a choice could be debatable, so I'll stop here.

  • Excellent answer!! In the last example you wrote ,\dots,n instead of ,\dotsc,n because we know how the sentence finish (different from ,\dotsc)? – manooooh Oct 1 '18 at 13:57
  • 1
    @manooooh Because \dots does a look ahead: if it finds a comma, then it's internally translated to \dotsc. – egreg Oct 1 '18 at 14:04

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.