4

I know that there is a typographical difference between using : and \colon in math mode, because : is considered to be a relation. However, I use \colon far more often than :, so I would like to interchange both. Is that possible?

red_trumpet
  • 995
  • 1
  • 6
  • 17

1 Answers1

6

\colon and : are defined in fontmath.ltx using:

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

which makes \colon a punctuation and : a relation symbol, as you said yourself.

You can swap the definitions:

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

As egreg noted, amsmath has a different definition of \colon, which does not rely on TeX's primitive math spacing. To swap the definitions of : and \colon with amsmath you need to make : a math-active character (I did that using egreg's \DeclareMathActive) and un-define \colon prior to using \DeclareMathSymbol:

\usepackage{amsmath}
% From https://tex.stackexchange.com/a/299805/134574
\newcommand{\DeclareMathActive}[2]{%
  \expandafter\edef\csname keep@#1@code\endcsname{\mathchar\the\mathcode`#1 }
  \begingroup\lccode`~=`#1\relax
  \lowercase{\endgroup\def~}{#2}%
  \AtBeginDocument{\mathcode`#1="8000 }}
\newcommand{\std}[1]{\csname keep@#1@code\endcsname}
% amsmath's definition of \colon:
\DeclareMathActive{:}{\nobreak\mskip2mu\mathpunct{}\nonscript
  \mkern-\thinmuskip{\std{:}}\mskip6muplus1mu\relax}
% undefine then redefine \colon:
\let\colon\UndefineD
\DeclareMathSymbol{\colon}{\mathrel}{operators}{"3A}