kvoptions と babel の非互換性

kvoptions と babel の非互換性

私はkvoptionsドキュメント クラスで使用しており、これまでのところうまく機能していましたが、大幅な書き換え後にパッケージに起因する奇妙なエラーが発生し始めましたbabel

MWE:

%% myclass.cls

\NeedsTeXFormat{LaTeX2e}[2018/04/01]
\ProvidesClass{myclass}

\RequirePackage[patch]{kvoptions}

\DeclareStringOption{title}
\ProcessKeyvalOptions*

\LoadClass{article}
\title{\myclass@title}
\RequirePackage[english]{babel}

\endinput
\documentclass[title={Here be dragons}]{myclass}

\begin{document}
Lorem Ipsum
\end{document}

ログからの抜粋 (簡潔にするためパスは省略):

babel.sty:460: LaTeX Error: Missing \begin{document}. [    {}}]
babel.sty:460: Too many }'s. [    {}}]
babel.sty:475: LaTeX Error: Missing \begin{document}. [    \ifin@\edef\bbl@tempc{\bbl@tempb}\fi}]

パッチを適用しないとkvoptions、エラーはさらに悪化します。

babel.sty:339: LaTeX Error: Missing \begin{document}. [\ProcessOptions*]
babel.sty:339: You can't use `macro parameter character #' in horizontal mode. [\ProcessOptions*]
TeX STOPPED: File ended while scanning use of \reserved@{##1,##2\reserved@b }\def \reserved@b ##1,\reserved@b ##2\reserved@b 
TeX reports the error was in file:3 
myclass.cls:13: LaTeX Error: Unknown option `english' for package `babel'. []

分析:問題は、グローバル オプション ( title) でスペース (および中括弧) を使用しており、このオプションが に渡されることが明らかなことですbabel。スペースがなければ、エラーは発生しません。

質問:ドキュメント クラス オプションがパッケージによってグローバル オプションとして使用されるのを防ぐことはできますか? または、オプションの代わりに を使用するための類似の回避策はありますか\hypersetup{}? それで問題ありません。

答え1

私はこの問題を、別の質問への答え上記の MWE に適用すると、次のようになります。

%% myclass.cls

\NeedsTeXFormat{LaTeX2e}[2018/04/01]
\ProvidesClass{myclass}

\RequirePackage{kvoptions}

\DeclareStringOption{title}
\ProcessKeyvalOptions*

\LoadClass{article}

\newcommand*{\docsetup}[1]{
  \kvsetkeys{myclass}{#1}
  \title{\myclass@title}
  \RequirePackage[english]{babel}
}

\endinput
\documentclass{myclass}
\docsetup{title={An awesome title}}

\begin{document}
Lorem Ipsum
\end{document}

関連情報