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?

  • 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." – Ulrike Fischer Feb 23 '23 at 19:57
  • 1
    Now it makes more sense! +1 – mickep Feb 23 '23 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? –  Feb 23 '23 at 20:03
  • What about just using $A:B$? – Werner Feb 23 '23 at 20:25
  • @Werner If "A:B" means "A has type B", sure. If "A:B" means "A such that B" (in variable bindings), we need less space before : than after it. My question was merely about what was the point of the current choice of spacing produced by \colon. –  Feb 23 '23 at 20:31
  • @Werner typing : gives a \mathrel. It might be what one wants, or not ;-) – campa Feb 23 '23 at 20:33
  • 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 '23 at 22:48
  • @Werner Good point. Already partially doing this macroification for some usages of the colon. –  Feb 23 '23 at 23:18

1 Answers1

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:}
egreg
  • 1,121,712
  • Thx! You wrote, “Whether this was a good decision by the AMS, it's debatable.” I don't wish to debate their decision as it might be too late to change anyway. Any rationale which AMS deemed to be valid when the decision was taken (beyond “f\colon A\to B looks nicer/better with our spacing”)? –  Feb 24 '23 at 19:34
  • 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, – barbara beeton Feb 24 '23 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 '23 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. – barbara beeton Feb 25 '23 at 01: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 '23 at 09:51
  • @barbarabeeton Did Mike Spivak participate on the introduction/definition of \colon? –  Mar 02 '23 at 02:16
  • @AlbertNash -- I very much doubt it. Mike spent a month at Stanford in summer 1979 as part of a group sent by the AMS to learn TeX, bring it back to Providence (to be put into its publications production), and create and document a user interface for such production (AMS-TeX). I'd have to check the original TeX78 manual to see what existed then (I have a copy, but it's in an inaccessible box). Although much changed between TeX78 and 82, it was mostly of a different nature: font handling, things in Appendix D, but the basics of most exposition were already solid, as I remember. – barbara beeton Mar 02 '23 at 03:37
  • @AlbertNash -- I've found the file of notes on AMS-TeX that Mike created. (He gave me permission to post them after a long negotiation.) They are the file amstex.txt in the directory https://ctan.org/tex-archive/macros/amstex/doc "colon" and \colon aren't mentioned at all, but there's an extensive note on \: immediately after the note on \binom. Keep the file amstex.tex open at the same time. This now exhausts my knowledge on the subject. – barbara beeton Mar 02 '23 at 04:00
  • @barbarabeeton I'm confused. Do you mean https://en.wikipedia.org/wiki/Michael_Spivak ? I see a long para concerning \: in amstex.txt. I don't understand all of it. The difference I see between amstex's \: and amsmath's \colon is that the former uses \hskip…em whereas the latter uses \mskip…mu and is robust. As for the usage, it indeed seems that \: (and, seemingly, \colon as being based on \:) “is for constructions like f:A --> B.” –  Mar 02 '23 at 22:56
  • @AlbertNash No line break can follow \colon for the simple reason that there's no \mathrel or \mathbin. If you add a penalty after \colon, then a line break becomes possible and the space is not removed, but you can do \unskip. – egreg Mar 02 '23 at 23:17
  • 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 02 '23 at 23:22
  • I was about to rewrite my comment, but you were faster. Thank you! –  Mar 02 '23 at 23:23
  • @egreg For a reason I don't understand, your \bcolon seems not to work (or at least I don't see how) in the sense that no line break is produced after the colon despite an overfull. Namely, https://pastebin.com/S0QUB0ux yields https://i.imgur.com/h2ugChZ.png. –  Mar 02 '23 at 23:32
  • @egreg I take it mostly back: if we replace 42em by 42.1em in pastebin.com/S0QUB0ux , a line break is produced in \bcolon. So thank you!!! –  Mar 02 '23 at 23:35
  • @barbarabeeton Concerning my original question about the use of the additional spacing, the sentences “… is for constructions like f:A --> B. Spacing was specified by AMS.” from the description of \: is the best we get, isn't it? –  Mar 02 '23 at 23:39
  • @egreg Any rationale on why \linebreak[0] instead of a simpler \penalty0? IMHO, \linebreak[0] does lots of stuff which is simply unnecessary in our particular case. –  Mar 03 '23 at 00:07
  • @AlbertNash Consistency with the official manual. – egreg Mar 03 '23 at 00:20
  • @egreg Same (i.e., consistency) for protection via \DeclareRobustCommand? Probably, \def or \newcommand would also suffice. –  Mar 03 '23 at 00:38
  • @egreg Also, anything in favor of or against an optional parameter saying what the penalty should be, as in \newcommand*{\bcolon}[1][50]{\nobreak\mskip2mu\mathpunct{}\nonscript\mkern-\thinmuskip{:}\penalty#1\mskip6muplus1mu\relax}, for instance? An alternative could be \newcommand*{\bcolon}[1][0]{\nobreak\mskip2mu\mathpunct{}\nonscript\mkern-\thinmuskip{:}\linebreak[#1]\mskip6muplus1mu\relax}. I'm not sure whether to say \newcommand or \newcommand* here. –  Mar 03 '23 at 03:16
  • 1
    @AlbertNash -- Yes, the documentation in amstex.txt is the best we can get. Ir at least the best I can come up with. Frank Mittelbach was one of the people responsible for converting AMS-TeX to AMS-LaTeX; it's possible he might remember something, but I doubt it. Sadly, both Mike Spivak and Michael Downes, the only other people involved with either AMS-TeX or amsmath, are no longer alive. – barbara beeton Mar 03 '23 at 05:06
  • @barbarabeeton Thank you, I see. I've just asked Frank via e-mail. –  Mar 03 '23 at 12:13
  • 1
    well I don't. We converted amstex 1-2-1 to amslatex as far as functionality is concerned and that is about all. What the reason was for the definition in amstex I don't know, back then our task was just to provide the equvialent of all the commands (and environments) in LaTeX. My guess is that Spivak followed some printing tradition that were used at the time but whether they were common or just something he saw ... who knows. – Frank Mittelbach Mar 03 '23 at 13:35
  • @barbarabeeton “The Joy of TeX” provides two more similar usages of \:. In my understanding, the goal still seems to be the introduction of a function symbol along with its domain and codomain. The first occurrence is in the solution to Exercise 7.10 (12): $f*g\:A\to B$ results in “ ∗ : → ”. The second is in the solution to Exercise 11.1 (5): $$\Sigma^2\:[X,S_0(\infty)]\to[\Sigma^2X,S_0(\infty)]$$ results in “Σ²: [, ₀(∞)] → [Σ², ₀(∞)]”. So no new usage patterns. (And no explanation of the chosen pre- and post-distances either.) –  Mar 05 '23 at 02:25
  • @barbarabeeton Here a bit of reverse-engineering the spacing in \def\:{\nobreak\hskip.1111em\mathpunct{}\nonscript\mkern-\thinmuskip{:}\hskip.3333emplus.0555em\relax} (which IMHO got translated to \colon). The pre-space .1111em is ≈ 1/9 em (= verythinmathspace of MathML = thousands separator added by \pu of MathJax/mhchem = half of the medium mathematical space U+205F), and the post-space .3333em plus .0555em is ≈ 1/3 em (= Three-Per-Em Space, U+2004) plus 1/18 em. –  Mar 05 '23 at 02:44
  • @barbarabeeton So my wild guess is that the intention of \: could have been to typeset “half of the math space : slightly stretchable Three-Per-Em Space”. –  Mar 05 '23 at 02:47
  • @FrankMittelbach I see. Thanks for replying anyway! Given that 1 mu = 1/18 em (cf. https://www.overleaf.com/learn/latex/Lengths_in_LaTeX), I see now why \hskip.1111em turned to \mskip2mu and \hskip.3333emplus.0555em turned to \mskip6muplus1mu when you translated \: to \colon. –  Mar 05 '23 at 02:59
  • @AlbertNash -- I'm not enough of a mathematician to understand the distinction between how Spivak defined \: and Knuth's definition of \colon. (I understand the conversion to \mskip units.) What I find unfortunate is the decision to reuse the name \colon, but it's far too late to do anything about that. – barbara beeton Mar 05 '23 at 04:35
  • @barbarabeeton I agree that ideally, Plain TeX's of \colon definition could have been kept. As for \:, an alternative wild guess to “half of the medium mathematical space : slightly stretchable Three-Per-Em Space” could have been “very thin math space : slightly stretchable Three-Per-Em Space”, of course, assuming that the concept of “very thin math space” existed back then. –  Mar 05 '23 at 16:34