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?
Asked
Active
Viewed 400 times
4
Phelype Oleinik
- 70,814
red_trumpet
- 995
- 1
- 6
- 17
1 Answers
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}
Phelype Oleinik
- 70,814
LaTeX Error: Command \\colon' already defined.The command for:` works though. Is there any way to "remove" commands? – red_trumpet Sep 22 '19 at 13:18\let\colon\relaxbefore the definition @red_trumpet – David Carlisle Sep 22 '19 at 13:20\let\colon\relaxor\let\colon\undefined. Related question – schtandard Sep 22 '19 at 13:21relaxandundefined? – red_trumpet Sep 22 '19 at 13:27\relaxis a "do-nothing", so usually if a command is equal to\relaxit is "free to be redefined".\undefinedis an undefined command.\SomethingImPrettySureIsNotDefinedwould've worked too. The error only appears if\colonis defined to be something else though... – Phelype Oleinik Sep 22 '19 at 13:30undefinedcommand results in an error (command not found), and using a\relaxed command just does nothing. Thanks! – red_trumpet Sep 22 '19 at 13:32\colonhas a different definition inamsmath. – egreg Sep 22 '19 at 13:36\UndefineDin my preamble and sue you when the code fails.;-)– Gaussler Aug 16 '22 at 10:28