12

What is the purpose of $:$?

We know that in math mode one should write in natural language and not being so strict with math notation.

For example: $f:A\to B$ is not "correct", the correct way would be $f\colon A\to B$ (and variants).

I do not remember any math book that uses the colon as part of a sentence in math mode.

The only 2 uses I can give to $:$ are when learning about divisions ($2:4=1:2$) and scales ($1:2$).

Does (La)TeX give a meaning of : in math mode?

manooooh
  • 3,203
  • 2
  • 21
  • 46
  • 2
    The colon is not used for division in USA/British tradition. In scale ratios, I'd prefer spacing the colon as a relation rather than an operation. – egreg May 16 '19 at 07:39

2 Answers2

12

The : is a relational symbol in TeX. In the TeXbook it is used in conjunction with =.

Plain \TeX\ treats the four characters |=|, |<|, |>|, and |:|\ as
``^{relations}'' because they express a relationship between two
quantities. For example, `${x<y}$' means that $x$~is less than~$y$.
Such relationships have a rather different meaning from binary
operations like $+$, and the symbols are typeset somewhat differently:
\beginmathdemo
|$x=y>z$|&x=y>z\cr
|$x:=y$|&x:=y\cr
|$x\le y\ne z$|&x\le y\ne z\cr
|$x\sim y\simeq z$|&x\sim y\simeq z\cr
|$x\equiv y\not\equiv z$|&x\equiv y\not\equiv z\cr
|$x\subset y\subseteq z$|&x\subset y\subseteq z\cr
\endmathdemo

In the comments, egreg pointed out another example in the TeXbook, where : is used to separate the condition from the set variable.

\beginmathdemo
|$\{\,x\mid x>5\,\}$|&\{\,x\mid x>5\,\}\cr
|$\{\,x:x>5\,\}$|&\{\,x:x>5\,\}\cr
\endmathdemo
(Some authors prefer to use a ^{colon} instead of `$\mid$', as in the second
example here.)

The colon has the exact same meaning in Plain TeX and LaTeX, as can be verified using this simple document:

\showthe\mathcode`:
\csname @@end\endcsname
\bye

The output is

$ pdftex test.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019) (preloaded format=pdftex)
 restricted \write18 enabled.
entering extended mode
(./test.tex
> 12346.
l.1 \showthe\mathcode`:

? 
 )
No pages of output.
Transcript written on test.log.
$ pdflatex test.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2018-12-01>
> 12346.
l.1 \showthe\mathcode`:

? 
 )
No pages of output.
Transcript written on test.log.

Here the same table rendered in LaTeX:

enter image description here

\documentclass{article}
\usepackage{array}
\usepackage{amsmath}
\usepackage{listings}
\lstset{basicstyle=\ttfamily}
\begin{document}
\lstMakeShortInline|
\begin{tabular}{l>{$}l<{$}}
|$x=y>z$|                 & x=y>z                 \\
|$x:=y$|                  & x:=y                  \\
|$x\le y\ne z$|           & x\le y\ne z           \\
|$x\sim y\simeq z$|       & x\sim y\simeq z       \\
|$x\equiv y\not\equiv z$| & x\equiv y\not\equiv z \\
|$x\subset y\subseteq z$| & x\subset y\subseteq z \\
\end{tabular}
\end{document}
Henri Menke
  • 109,596
  • 4
    I think := should be typeset with \coloneqq: https://tex.stackexchange.com/a/4217/156344. One should not use $a:=b$ as Knuth said. –  May 16 '19 at 06:25
  • The claim that : "is intended to be used in conjunction with =" seems a bit too strong. E.g., it seems perfectly ok to use : to denote conditioning on an event. (See my answer for a specific example.) – Mico May 16 '19 at 06:46
  • If you inspect the typeset version of := closely, you'll notice that the colon symbol is centered vertically on the equals symbol. Not good, at least not for math-typesetting gourmets. That's why it's useful to write \coloneq, \coloneqq, etc. – Mico May 16 '19 at 06:49
  • @JouleV That is an entirely different question than the one asked by OP. – Henri Menke May 16 '19 at 07:31
  • @Mico If you use a good typesetting system like ConTeXt, it will automatically “ligature” := into . – Henri Menke May 16 '19 at 07:32
  • 3
    @Mico If you look in the Metafontbook, you will see “:=” clearly input as :=. Whether the mathtools macros \coloneqq should be used is a question of personal choice and taste (I would never use := in my math, of course). I agree that := is by no means “the” intended usage (see page 174 in the TeXbook for the main one). In proportions such as a:b=c:d I'd not treat the colon as a binary operation. – egreg May 16 '19 at 07:36
  • @egreg I hold against your claim that := is not the intended usage by pointing out exercise 18.9. – Henri Menke May 16 '19 at 07:44
  • 1
    @HenriMenke It is not “the” (in the sense of the unique) intended usage. – egreg May 16 '19 at 07:53
  • 1
    @JouleV -- While \coloneqq exists now (and should now be used), it did not exist when TeX was created -- there simply wasn't enough memory to accommodate all possible symbols. – barbara beeton May 16 '19 at 13:33
  • @barbarabeeton Yes. So what I mean is that, : was meaningful, but is meaningless. –  May 16 '19 at 14:35
  • 1
    @egreg For := I use always your \mathrel{\mathop:}= :-) from Comprensive list symbols. – Sebastiano May 16 '19 at 15:08
  • @Sebastiano good to know! – manooooh May 16 '19 at 23:06
  • @HenriMenke you have provided an answer regarding TeX. What about LaTeX? Thanks. – manooooh May 16 '19 at 23:07
  • 1
    @manooooh The colon has the exact same meaning in TeX and LaTeX. I added a simple document to verify this to my answer. – Henri Menke May 16 '19 at 23:56
7

Quite often, one sees : employed in place of a vertical bar (|) to denote conditioning on some event or condition. E.g., both $E(X : X>0)$ and $E(X\mid X>0)$ would express the "expectation of the random variable X conditional on this random variable taking on positive values".

By default, TeX treats both : and \mid -- but not | and \vert -- as "relational" operators and inserts an amount of whitespace around them that's also used for other relational operators such as <, =, and >.

For other, i.e., non-conditioning math uses of the colon symbol, one should employ \colon, \coloneq (or, depending on the package that's in use, \coloneqq, etc.

Mico
  • 506,678