2

In math, I exclusively use the colon : for punctuation, i.e. in the sense of \colon (compare this question). Hence I would like to change the way : is being typeset, so that it resembles \colon.

Is there a way to achieve this in XeTeX / unicode-math?

2 Answers 2

3
\documentclass{article} 
\usepackage{amsmath}
\begin{document} 
$\forall x: P (x)$  using \verb|:|

$\forall x \colon P(x)$ using \verb|\colon|

\def\newcolon{%
  \nobreak\mskip2mu\mathpunct{}\nonscript\mkern-\thinmuskip{\text{:}}%
  \mskip 6mu plus 1 mu \relax}

\mathcode`\:="8000 %
{\catcode`:=\active \global\let:\newcolon}

$\forall x: P (x)$ using revised \verb|:|

$\scriptstyle \forall x: P (x)$

$\scriptscriptstyle \forall x: P (x)$

\end{document}

enter image description here

14
  • This sends TeX into infinite loop if used along with \usepackage[french]{babel}. Anyway, \number is not needed after \mathcode.
    – egreg
    Feb 14, 2020 at 20:31
  • @egreg Thanks for noting both points. Removed \number...don't know how to resolve babel issue. Feb 14, 2020 at 20:33
  • Thanks so much for your answer! I honestly don't see a difference between \colon and your \newcolon, though? (:
    – balu
    Feb 14, 2020 at 21:51
  • 1
    @balu As to the italic, changing the {\text{:}} in my definition to {\text{\textup{:}}} will do it. However, the 1st version approach of egreg does not suffer this issue, in which you define \mathchardef\normalcolon=\mathcode`: and then replace in my definition {\text{:}} with {\normalcolon}. Feb 14, 2020 at 23:07
  • 1
    @balu That is correct...\colon is defined in terms of math :, so defining : in terms of \colon creates an infinite loop. Here, \newcolon is defined in terms of a non-math colon. Feb 15, 2020 at 21:49
1

If you're not French and plan to never write in French, you can just do

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\mathchardef\normalcolon=\mathcode`:
\def\colon{%
  \noexpand\nobreak
  \mskip 2mu
  \mathpunct{}
  \nonscript\mkern -\thinmuskip
  {\normalcolon}%
  \mskip 6muplus1mu
  \relax
}
\begingroup\lccode`\~=`\:\lowercase{\endgroup\let~}\colon
\mathcode`\:=\string"8000
\makeatother

\begin{document}

$f: A \to B$

$a\normalcolon b$

\end{document}

This would send TeX into infinite loop if babel-french is used. A safer patch:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{amsmath}

\makeatletter
\mathchardef\normalcolon=\mathcode`:
\def\colon{%
  \noexpand\nobreak
  \mskip 2mu
  \mathpunct{}
  \nonscript\mkern -\thinmuskip
  {\normalcolon}%
  \mskip 6muplus1mu
  \relax
}
\@ifpackagewith{babel}{french}{% french babel makes : active
  \declare@shorthand{french}{:}{%
    \ifmmode % <--- added
      \colon % <--- added
    \else % <--- added
      \ifFB@spacing
        \ifhmode
          \ifdim\lastskip>1sp
            \unskip\penalty\@M\FBcolonspace
          \else
            \FDP@colonspace
          \fi
        \fi
      \fi
      \string:%
    \fi % <--- added
  }%
}{%
  \begingroup\lccode`\~=`\:\lowercase{\endgroup\let~}\colon
  \mathcode`\:=\string"8000
}
\makeatother

\begin{document}

$f: A \to B$

$a\normalcolon b$

\end{document}

enter image description here

You can still use \colon with the standard meaning. For the colon as relation symbol (what you get normally in TeX with :) I provided \normalcolon.

Disclaimer. This doesn't work with XeLaTeX or LuaLaTeX.

You must log in to answer this question.

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