![\shorthandon と \shorthandoff を他のマクロに埋め込むことができないのはなぜですか?](https://rvso.com/image/286988/%5Cshorthandon%20%E3%81%A8%20%5Cshorthandoff%20%E3%82%92%E4%BB%96%E3%81%AE%E3%83%9E%E3%82%AF%E3%83%AD%E3%81%AB%E5%9F%8B%E3%82%81%E8%BE%BC%E3%82%80%E3%81%93%E3%81%A8%E3%81%8C%E3%81%A7%E3%81%8D%E3%81%AA%E3%81%84%E3%81%AE%E3%81%AF%E3%81%AA%E3%81%9C%E3%81%A7%E3%81%99%E3%81%8B%3F.png)
\title
マクロを で囲む\shorthandon{;:!?}
と、の言語\shorthandoff{;:!?}
で期待される結果が得られます( '?'、 '!'、 ':'、 ';' の前にスペースが追加されます)。babel
french
\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
\maketitle
babel-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}
。