如何在自訂類別中強制某些選項並放棄其他選項?

如何在自訂類別中強制某些選項並放棄其他選項?

我正在創建一個基於memoir.為此,我允許將多個類別選項傳遞給我的程式碼。無法識別的選項將簡單地傳遞到memoir.

a4paper現在我的問題是:即使我的班級的使用者letterpaper作為選項通過,我該如何強制?換句話說:是否可以停用其他文件大小選項(letterpapera5paperebook等),同時保留可以傳遞ms或等選項fleqn

答案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}

相關內容