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?

1 Answer 1

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}
10
  • With that I get: LaTeX Error: Command `\colon' already defined. The command for : works though. Is there any way to "remove" commands? Sep 22, 2019 at 13:18
  • 1
    put \let\colon\relax before the definition @red_trumpet Sep 22, 2019 at 13:20
  • 1
    @red_trumpet \let\colon\relax or \let\colon\undefined. Related question
    – schtandard
    Sep 22, 2019 at 13:21
  • Thanks now it works! What's the difference between relax and undefined? Sep 22, 2019 at 13:27
  • @red_trumpet What they said :-) \relax is a "do-nothing", so usually if a command is equal to \relax it is "free to be redefined". \undefined is an undefined command. \SomethingImPrettySureIsNotDefined would've worked too. The error only appears if \colon is defined to be something else though... Sep 22, 2019 at 13:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .