Why \shorthandon and \shorthandoff cannot be embedded in other macros?

Surrounding \title macro with \shorthandon{;:!?} and \shorthandoff{;:!?} gives the expected result with babel's french language (space added before the '?', '!', ':' and ';'):

\documentclass[french]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
%
\shorthandon{;:!?}%
\title{La crise? Quelle crise?}
\shorthandoff{;:!?}%
%
\begin{document}
\maketitle
\end{document}


But this doesn't work if \shorthandon and \shorthandoff are embedded in (a redefinition of) the \title macro:

\documentclass[french]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
%
\let\titleORI\title
\renewcommand{\title}[1]{%
\shorthandon{;:!?}%
\titleORI{#1}%
\shorthandoff{;:!?}%
}
%
\title{La crise? Quelle crise?}
\author{Un auteur? Deux auteurs!}
%
\begin{document}
\maketitle
\end{document}


What is the reason of this? Is there a workaround?

-
catcode changes always have the same restriction, same as \verb not working in a macro argument. –  David Carlisle Mar 25 '14 at 14:19

Saying \shorthandon{?} makes ? an active character. So, when the argument to \title is absorbed, in the first example, it is active and, at \maketitle, LaTeX will use the current definition for it, which happens to be the one defined by babel-french.

On the contrary, in the second case the \shorthandon command is executed when the argument to \title has already been absorbed, so ? is not active and such it will remain forever (in the replacement text of \@title, which is the macro where \title stores the title).

You have to delay reading the argument after \shorthandon has been executed.

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

\let\ORItitle\title
\renewcommand{\title}{%
\shorthandon{;:!?}%
\titlewithshorthand
}
\newcommand{\titlewithshorthand}[1]{%
\ORItitle{#1}%
\shorthandoff{;:!?}%
}

\title{La crise? Quelle crise?}

\begin{document}
\maketitle
\end{document}


But I'd simply place \title after \begin{document}.

-
Placing \title after \begin{document}, and before \maketitle, is natural (and in any case necessary) as the corresponding argument will appear in the 'made' title. But, back to my other question tex.stackexchange.com/q/166878/18401, for other macros from a custom class, such as \keywords, it is not natural to impose its insertion before \maketitle. Hence, I would prefer to store all these 'document properties' macros (\title, \keywords, etc.) in the preamble, with the drawback of these characters active only at \begin{document}. –  Denis Bitouzé Mar 25 '14 at 14:41
With babel 3.9 there's the KeepShorthandsActive option, but I wouldn't recommend it for general usage. –  egreg Mar 25 '14 at 14:45
Yes: looks very dangerous! :) I prefer your solution that confines the shorthands deactivation. –  Denis Bitouzé Mar 25 '14 at 14:50
@egreg And with 3.8, in fact. This is one of the oldest options of babel. –  Javier Bezos Mar 25 '14 at 17:45
@JavierBezos Really? Well, I've always recommended putting \title and \author after \begin{document}. ;-) –  egreg Mar 25 '14 at 17:47