138

I noticed that in many documents you encounter $f: X \to Y$ instead of $f \colon X \to Y$. Another example are quantified expressions: $\forall x: P (x)$ versus $\forall x \colon P(x)$. I find the \colon visually more pleasing, however I sometimes think I seem to be the only one, given the overwhelming amount of documents that seem to use :. Is there a rule of thumb to decide where you should use either \colon or :?

blubb
  • 1,711

3 Answers3

159

Both : and \colon typeset a colon, but \colon is a punctuation symbol, while : is considered as a relation symbol as regards to spacing.

The main use of : is in set descriptions

\{\, x : x \notin x \,\}

(somebody uses \mid for this, where a simple | would be wrong; thin spaces after \{ and before \} are recommended by Knuth, be consistent in using them or not).

Conversely, \colon should be used for mappings

f\colon A \to B

but unfortunately many writers don't make this distinction and use :, getting a wrong spacing.

The rule to follow is just the same: use \colon when it's a "punctuation colon", use : when it represents a relation between what's at its left and at its right. In something like "for all x:" I would consider the colon as punctuation, so \forall x\colon

Note that the amsmath package changes the definition of \colon so that it's not exactly the same as a punctuation symbol:

\renewcommand{\colon}{\nobreak\mskip2mu\mathpunct{}\nonscript
  \mkern-\thinmuskip{:}\mskip6muplus1mu\relax}

This adds a bit of space before the colon, which seems more right than with a simple \mathpunct.

egreg
  • 1,121,712
  • 9
    And use : for ratios. e.g. $x:y:z = 3:4:5$. – Leo Liu Dec 10 '11 at 11:25
  • 12
    @LeoLiu Alternatively, \mathbin{:} could be used. Which one is a matter of personal taste. Most important is consistency across the document. – egreg Dec 10 '11 at 11:32
  • 35
    How does one distinguish between "punctuation" and "relation"? The notation f\colon A\to B does denote a relation between f and A\to B, namely the relation "has type". And I don't see in what sense the colon in \{\, x : x\notin x \,\} denotes a "relation" between x and x\notin x. – Mike Shulman Apr 11 '12 at 10:29
  • 5
    @MikeShulman It's a matter of conventions; usually the colon for maps is considered as punctuation, the one in set descriptions as a relation symbol. Be coherent in your document. – egreg Apr 11 '12 at 12:30
  • There's also a colon product, isn't there? I'd start typing the equation here as $\mathbf{AB}\mathbin{:}\mathbf{CD}..., since the colon appears to be a binary operator. – MSC May 05 '12 at 00:09
  • 12
    Just for clarity, the usual recommendation to use \, after \{ and before the matching \} is only in case the set involves a set descriptor (with the colon). By contrast, use \{a, b, c\} without the thin spaces in case of an explicit enumeration of elements. – murray Jun 27 '12 at 21:00
  • @egreg (or anybody else): Would it also be correct to use : when we typeset sets of the form \{\, x\in\mathbb{R} : x\notin x \,\} ? The difference is now the introduction of \in\mathbb{R}, which might obscure the objects that we want to relate to one-another (and rewriting the set as \{\, \mathbb{R}\ni x : x\notin x \,\} is not an option). – l7ll7 Sep 04 '15 at 17:20
  • 3
    Can you clarify in your answer what objective criterion makes the spacing in $f : A \to B "wrong"? Or, if this is an opinion, however widely (?) held, can you make that explicit? Maybe many of the writers you refer to actively choose that option because it looks better (e.g. less cramped) to them. – E.P. Nov 09 '16 at 18:51
  • 2
    @E.P. I follow the AMS in this (and Knuth). – egreg Nov 09 '16 at 20:35
  • 3
    @egreg Ah, I see. It would be good to state that explicitly. The left-of-colon spacing in $f \colon A \to B$ changes quite dramatically depending on whether amsmath is called or not (as you explain). In any case, that spacing is a subjective matter of taste, so claiming it is objectively wrong is not quite there. – E.P. Nov 09 '16 at 22:29
  • And what if you use the colon as a division sign, like they do in some countries? Which one in that case? – Andyc May 25 '21 at 19:38
  • 2
    @Andyc \mathbin: – egreg May 25 '21 at 21:10
17

If you're trying to typeset a variable-has-type colon in type theory, you want {:} or \mathord{:} (they display the same). For example, you'll get a nice looking STLC identity function with $\lambda x {:} A . x$.

See this page for a more general discussion.

ntc2
  • 355
1

OpTeX sets the : differently when its Unicode math is loaded. The reason is that MathClass-15.txt defines the : as punctuation mark. We left the plain TeX setting of : as relation and keep Unicode recommendation: : is \mathpunct.

Consequences: you can type $f: A → B$ and the result is OK. Of course, there is slightly smaller spaces than LaTeX's \colon from amsmath does, but IMHO LaTeX defines \colon with bigger spaces than needed (because it is a bad compromise between Plain TeX default : as relation and desired punctuation). OpTeX is without compromises, the : is punctuation and you can type it naturally without any control sequences.

On the other hand, in cases like $x \mathbin: y$ you need to use a TeX primitive control sequence \mathbin or \mathrel to get good spaces.

The reason of this decision is: the usage of : as $f: A → B$ is much more common in math typesetting than usage of : in all other situations.

wipet
  • 74,238