\shorthandon と \shorthandoff を他のマクロに埋め込むことができないのはなぜですか?

\shorthandon と \shorthandoff を他のマクロに埋め込むことができないのはなぜですか?

\titleマクロを で囲む\shorthandon{;:!?}と、の言語\shorthandoff{;:!?}で期待される結果が得られます( '?'、 '!'、 ':'、 ';' の前にスペースが追加されます)。babelfrench

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

\shorthandonしかし、 と が\shorthandoffマクロ (の再定義) に埋め込まれている場合は、これは機能しません\title

\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}

その理由は何でしょうか? 回避策はありますか?

答え1

とすると、アクティブな文字\shorthandon{?}が作成されます。したがって、最初の例では、?への引数が吸収されると、それはアクティブになり、 では、LaTeX は によって定義された現在の定義を使用します。\title\maketitlebabel-french

逆に、2 番目のケースでは、\shorthandon引数が\titleすでに吸収されているときにコマンドが実行されるため、 は?アクティブではなく、永久に残ります ( の置換テキスト内\@title、つまりタイトルを格納するマクロ内\title)。

\shorthandon実行後に引数の読み取りを遅延する必要があります。

\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}

しかし、私は単に\titleの後にを配置します\begin{document}

関連情報