%%
%% The LaTeX Companion, 3ed
%%
%% Example A-4-3 on page II-676 in "Important generic hooks are available out of the box".
%%
%% Copyright (C) 2022 Frank Mittelbach
%%
%% It may be distributed and/or modified under the conditions
%% of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%%
%% See https://www.latex-project.org/lppl.txt for details.
%%

\documentclass{tlc3exa}
\pagestyle{empty}
\setcounter{page}{6}
\setlength\textwidth{147.0pt}

%StartShownPreambleCommands
\NewCommandCopy\ltxcolon\colon  % save LaTeX's definition
\usepackage{amsmath}
%StopShownPreambleCommands

\begin{document}
$ f \ltxcolon A\to B $ \hfill in standard \LaTeX \par
$ f \colon    A\to B $ \hfill in \texttt{amsmath}\par
\AddToHook{cmd/colon/after}{\!}
$ f \colon    A\to B $ \hfill in our version
\end{document}