カスタム クラスで一部のオプションを強制し、他のオプションを破棄するにはどうすればよいですか?

カスタム クラスで一部のオプションを強制し、他のオプションを破棄するにはどうすればよいですか?

に基づいてドキュメント クラスを作成していますmemoir。このため、いくつかのクラス オプションをコードに渡すことを許可します。認識されないオプションは、単に に渡されますmemoir

ここで質問です。a4paperクラスのユーザーが をletterpaperオプションとして渡した場合でも、どうすれば強制できるでしょうか。言い換えると、やなどのオプションを渡すことは可能なまま、他のドキュメント サイズ オプション ( letterpapera5paperebookなど) を無効にすることは可能でしょうか。msfleqn

答え1

私は次のことを提案します:

% declare options that should be passed to your code
% ...

% now specify which memoir options should not be used, using the following helper macro
\newcommand\warningoptionnotused@myclass
{%
  \OptionNotUsed%
  \ClassWarning{myclass}%
  {%
    Option '\CurrentOption'\space is incompatible with class
    `myclass' and will be ignored.
  }
}
\DeclareOption{letterpaper}{\warningoptionnotused@myclass}
\DeclareOption{a5paper}{\warningoptionnotused@myclass}
\DeclareOption{ebook}{\warningoptionnotused@myclass}
% do the same for all options that should be discarded...

% pass all other options to memoir
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{memoir}}

% process options
\ProcessOptions\relax

% then load memoir with the desired options
\LoadClass[a4paper]{memoir}

関連情報