基于这个答案我可以验证选项是否已设置为特定值。但如果实际值无关紧要,我该如何验证选项是否已设置。即,我如何确保选项确实设置为某个值?
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{testclass}[2017/02/14 v1.0 My test class]
\RequirePackage{kvoptions}
\SetupKeyvalOptions{
family=TEST,
prefix=TEST@
}
\DeclareStringOption{testoption}
\ProcessKeyvalOptions*
% ... how do I verify that testoption was set?
答案1
\DeclareStringOption
使用空字符串作为选项值的初始值作为默认值。以下示例将初始值设置为\relax
,以便在选项处理后可以检查这一点:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{testclass}[2017/02/14 v1.0 My test class]
\RequirePackage{kvoptions}
\SetupKeyvalOptions{
family=TEST,
prefix=TEST@
}
\DeclareStringOption{testoption}
% Override initial value for option `testoption`
\let\TEST@testoption\relax
\ProcessKeyvalOptions*
\ifx\TEST@testoption\relax
\ClassWarning{testclass}{Option `testoption' is not set.}
\else
\typeout{Option `testoption' is set to `\TEST@testoption'.}
\fi