# French spacing disappears within commands

I am preparing a document in French, using the "babel" package with option "french" and using commands that include colons and semicolons. My problem is, the French spacing before colons and semicolons disappears when the commands are printed. I do not understand why, have not been able to find an answer. Below is a MWE.

\documentclass{article}
\usepackage[french]{babel}
\newcommand\deuxpoints{Texte: texte}
\begin{document}
\deuxpoints\
\endgraf
Texte: texte
\end{document}


• My guess is that when you define \deuxpoints the colon is not yet active. You can get what a space if you define \deuxpoints after \begin{document} – moewe Jun 23 '18 at 16:00
• That is it. Very stupid of me not to have thought of that. Thanks a lot. – Rpy Jun 23 '18 at 16:03
• By the way, this is the main reason, IIRC, why the KOMA-Script manual suggests to use the \title, \author, etc. macros after the \begin{document}. To have any active characters in the arguments behave normally, as in the rest of the document. – frougon Jun 23 '18 at 16:07

As pointed to in the previous comments, babel set the active characters :!?; only at \begin{document}, by using \AtBeginDocument.
One could keep the definition in the preamble by using the command \shorthandon{:} just before the definiion of \deuxpoints and \shorthandff{:} just after.
Another solution is to add the KeepShorthandsActive in the option passed to babel.
Surprisingly, the etoolbox hook \AfterEndPreamble would be supposed to fix the problem but does not directly work.
• \AfterEndPreamble tokens will be executed when shorthands are not yet activated. – egreg Jun 24 '18 at 14:07