3

When looking at https://tex.stackexchange.com/a/64435, it seems to me that \mathpunct{:} and \colon should be interchangeable. But with amsmath, or NewTX, or unicode-math + TeX Gyre Termes Math, they are not. The documentation of unicode-math says that \colon from amsmath is used. Why the additional spacing? What's the point?

The second line of the output of

\documentclass{article}
\pagestyle{empty}
\usepackage{iftex}
\ifTUTeX
\usepackage[math-style=ISO]{unicode-math}
\setmainfont{TeX Gyre Termes}
\setmathfont{TeX Gyre Termes Math}
\else
\usepackage{newtxtext,newtxmath}
% \usepackage{amsmath}%%% alternative
\fi
\begin{document}
\noindent
A$\mathpunct{:}$B\\
A$\colon$B\\
$A\mathpunct{:}B$\\
$A\colon B$
\end{document}

is A : B regardless of whether we compile with pdflatex or lualatex:

output

(Though you may or may not wish spacing in line 4.) In particular, when \colon happens to end the line, say, \colon\\, there's some space between it and the right margin. I don't see any point in it.

By the way, how much spacing does \colon insert before and after : exactly?

8
  • well the soon to appear new latex companion says "However, the amsmath package makes unfortunate major changes to the spacing produced by the command \colon so that it is useful only for a particular layout in constructions such as f\colon A\to B .... It is therefore wise to always use \mathpunct{:} for the simple punctuation colon in mathematics." Feb 23, 2023 at 19:57
  • 1
    Now it makes more sense! +1
    – mickep
    Feb 23, 2023 at 20:00
  • @UlrikeFischer Oh. So f\colon A\to B might make sense. How about formulas with quantifiers, say, \forall\, x\in X\colon\varphi? Is the spacing around : there meant to be like this?
    – user282514
    Feb 23, 2023 at 20:03
  • What about just using $A:B$?
    – Werner
    Feb 23, 2023 at 20:25
  • 1
    @AlbertNash: Regardless of the choice, it's best to define some macro that inserts your desired symbol (and spacing). This way you can change it later if you find something needs to. It provides an easy way to yield consistent typography. So, I'd advise against using \mathpunct{:} everywhere it's needed, and define something like \newcommand{\hastype}{\mathpunct{:}} or similar and use A \hastype B in your document.
    – Werner
    Feb 23, 2023 at 22:48

1 Answer 1

2

They aren't interchangeable as soon as you load amsmath.

Indeed, the kernel definition of \colon is

\DeclareMathSymbol{\colon}{\mathpunct}{operators}{"3A}

whereas amsmath redefines it to

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

Whether this was a good decision by the AMS, it's debatable. On the other hand, the TeXbook uses \colon in just a few places

  • page 134, where f:A\to B and f\colon A\to B are compared
  • page 438, where again function notation is mentioned, but also the contrived example L(a,b;c\colon x,y;z)

The in-house style of AMS is that the colon for function notation is spaced differently: in particular it should have some space at its left and more space than with punctuation at its right.

If you want a “punctuation colon”, define your own command, say

\DeclareMathSymbol{\pcolon}{\mathpunct}{operators}{"3A}

Or (but I wouldn't recommend doing so) revert the amsmath definition with

\let\colon\relax
\DeclareMathSymbol{\colon}{\mathpunct}{operators}{"3A}

if you so prefer. Or

\DeclareRobustCommand{\colon}{\mathpunct:}
28
  • 1
    The \DeclareRobustCommand{\colon} is not the original AMS definition. (Commands weren't robustified until after amsmath was turned over to the LaTeX team.) I'm trying to find the original AMS amsmath definition, and will report it when I find it, Feb 24, 2023 at 23:26
  • 1
    @barbarabeeton In amsmath.sty, version 2.14 (the oldest I have on my machine) the definition is the same, just using \renewcommand instead of \DeclareRobustCommand. The oldest on the TeX Live site is 2.13 dated 2000/07/18 and the definition is the same. As far as I can see, Spivak's amstex.tex doesn't redefine \colon
    – egreg
    Feb 24, 2023 at 23:41
  • 1
    @egreg -- I've found in amstex.tex a definition of \: that expands to what looks like the same as that of \colon in amsmath.sty. In the base latex code, \: is defined to be \medspace, so it was no doubt a good idea to avoid that conflict. I can't say why \colon wasn't also avoided; looking at it carefully, I think it should have. (I didn't actually realize that it was redefined; I'm still inextricably philosophically bound to the plain definition.) I'm still looking for some "private" notes that Mike Spivak provided; he was unwilling to make them public. Feb 25, 2023 at 1:47
  • 1
    @barbarabeeton Yes, now I seem to remember. A pity that the usage of \: was confined to the solution of an exercise. My guess is that at the AMS it was decided that \colon would be the most used user input and so it was changed to give the “better” output.
    – egreg
    Feb 25, 2023 at 9:51
  • 1
    @AlbertNash You might define \newcommand{\bcolon}{\nobreak\mskip2mu\mathpunct{}\nonscript\mkern-\thinmuskip{:}\linebreak[0]\mskip6muplus1mu\relax} so a break after : becomes possible, but not encouraged, and the space would disappear at the break. But the discussion is taking nowhere: if you don't want to use \colon as defined by amsmath you either redefine it or define your own command.
    – egreg
    Mar 2, 2023 at 23:22

You must log in to answer this question.