# : is set to \colon, but the spacing is still wrong - part 2

This question explains how to make : behave as \colon. It has two solutions. The present question concerns the second, less upvoted solution, egreg solution, as in this question of mine, it turned out that the most upvoted solution, Carlisle's solution, is problematic when usd together with amsmath. Since I want to use that package, I have to consider egregs solution.

This solution has some rough edges, which is what this question is about: It also pretains to := and =: and there is a difference to using \coloneqq resp. \eqqcolon, as can be seen in

\begin{gather*}
a:=b=:c=d\\
a\coloneqq b \eqqcolon c = d
\end{gather*}


which displays as

so the spacing is a bit different, compared to the spacing of the commands in mathtools -- look at the red line and at the (barely visible) dotted orange vertical that I draw additionally on top of the screenshot, that make the spacing differences apparent.

Question 1: Why is there a difference ?

Question 2: In his solution, egreg is somewhat contradictory: After his wizardry, ´:=´ looks like \coloneqq (except that the spacing is different, as illustrated above) and also provides an example of this in this MWE - but in the comments he goes on to say, that one shouldn't use :=. Why has he then provided it in his MWE ? Should I or should I not use := ? In case both are considered good practice, which one should be used, when one wants to create professional looking documents ?

• See fixed code in my old answer. But I still think that exchanging the meanings of : and \colon is wrong. Sep 2 '15 at 16:15
• @egreg Thanks! Could you tell me why you think that is wrong ? After all, it would speed up typing (long) texts, as writing \colon take more time then a short :. BTW, if you could make this comment an answer (and also answer question 2) I'd be very happy to accept it, so that this question is done! Sep 2 '15 at 16:32
• I'd guess it's wrong because : is valid (and common) punctuation. Also, this is more likely to be dupe'd to the other question now :) Sep 2 '15 at 17:01

You can provide the colon with some “intelligence” in math mode

\documentclass{scrartcl}

\usepackage{mathtools}

\makeatletter
\def\ordinarycolon{\mathchar\:}
\def\colon{\nobreak\mskip2mu\mathpunct{}\nonscript\mkern-\thinmuskip\mathord\ordinarycolon\mskip6muplus1mu\relax}
\begingroup\lccode\~=\:\lowercase{\endgroup
\protected\def~}{\new@ifnextchar={\coloneqq\@gobble}{\colon}}
\begingroup\lccode\~=\=\lowercase{\endgroup
\protected\def~}{\new@ifnextchar:{\eqqcolon\@gobble}{\mathrel\mathchar\=}}
\AtBeginDocument{\mathcode\:="8000 \mathcode\=="8000 }
\makeatother

\begin{document}

\begin{gather*}
f : \mathbf{R} \to \mathbf{R} \\
a := b =: c = d \\
a \coloneqq b \eqqcolon c = d
\end{gather*}

\end{document}