# Keep babel's automatic spacing in \newcommand

In French, there's a narrow non-breaking space before ":". These are automatically added by the babel package, of course. However, I noticed something strange: the following macro

\newcommand{\abc}{abc: abc}

produces "abc: abc", without the narrow space. Thus, in the following MWE, the two output lines are different (the one produced with the macro looks like "abc: abc" while the other is correctly typeset as "abc : abc"), and I expected them to be the same:

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

\newcommand{\abc}{abc: abc}

\begin{document}

\abc

abc: abc

\end{document}


I searched for some times for a solution and mostly found people complaining about the spacing after a macro, so it wasn't very helpful… Of course I can write "~:", but it would be very surprising if there wasn't a better solution. It's weird that it took me several years to run into this problem. Maybe it has to do with the fact that I'm on Debian today instead of Ubuntu, but that sound a bit far-fetched. Any help will be much appreciated!

(pdfTeX 3.1415926-2.4-1.40.13 (TeX Live 2012/Debian))

• pass \newcommand{\abc}{abc: abc} after \begin{document} – touhami Mar 20 '16 at 16:37
• Wow, you're right. A bit weird, but not ugly at all, actually. I guess babel acts differently before and after \begin{document}. Thanks a lot! Now I kinda wonder whether every command should come after \begin{document} – M. M. Mar 20 '16 at 16:51

The babel package has a package option KeepShorthandsActive which allows shorthands to be used in the preamble:

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

\newcommand{\abc}{abc: abc}

\begin{document}

\abc

abc: abc

\end{document}