![将 kvoption DefaultOption 转发到 StringOption](https://linux22.com/image/430697/%E5%B0%86%20kvoption%20DefaultOption%20%E8%BD%AC%E5%8F%91%E5%88%B0%20StringOption.png)
我想对一个包使用 kvoptions,带有一个字符串选项,并且我希望将未知选项用作该字符串选项的值。像这样:
\ProvidesPackage{kvo}[2020/10/20 v 0.01 playing with kvoptions]
\RequirePackage{kvoptions}
\SetupKeyvalOptions{family=cdr,prefix=cdr@,setkeys=\kvsetkeys}
\DeclareStringOption{bla}
\AddToKeyvalOption*{bla}{
\immediate\write16{Option bla set to #1 which is the same as \cdr@bla. ***}
}
\DeclareDefaultOption{
\immediate\write16{Default option: \CurrentOption}
\kvsetkeys{cdr}{bla=\CurrentOption}
\immediate\write16{Now cdr@bla is \cdr@bla}
}
\ProcessKeyvalOptions*
因此我期望\usepackage[toto]{kvo}
将其设置\cdr@bla
为toto
。测试一下:
\documentclass{article}
\usepackage[toto]{kvo}
\begin{document}
\makeatletter
\immediate\write16{And now cdr@bla is \cdr@bla.}
\makeatother
\end{document}
我的输出中的相关行如下:
Default option: toto
Option bla set to toto which is the same as toto. ***
Now cdr@bla is toto
And now cdr@bla is .
发生了什么事导致 的值丢失\cdr@bla
?实现我想要的正确方法是什么,即将默认选项转移到字符串选项的设置?
我知道我可以说\xdef\cdr@bla{\CurrentOption}
这可行,但如果设置选项bla
有副作用,那就意味着重复代码,或者从两个地方调用相同的宏,我会发现这不太可读。