下面的简单包的代码mypkg.sty
定义了 key draft
。如果draft
作为类选项给出,LaTeX 会在命令处挂起\ProcessKeysOptions
。这似乎是一个错误。或者我的代码有问题?
打包文件mypkg.sty
:
\RequirePackage{expl3}
\RequirePackage{l3keys2e}
\ProvidesExplPackage{mypkg}{2011/05/06}{0.1}{triv. example pkg.}
\newcommand\isdraft{no}
\keys_define:nn{mypkg}{
draft .choice:,
draft / true .code:n = {\renewcommand\isdraft{yes}},
draft / false .code:n = {\renewcommand\isdraft{no}},
draft .default:n = {true}
}
\ProcessKeysOptions{mypkg}
测试文件:
\documentclass[draft]{article} %LaTeX hangs at \ProcessKeysOptions{...}
\usepackage{mypkg}
\begin{document}
Draft mode: \isdraft.
\end{document}
答案1
l3keys2e
函数中有一个字母的错误:
\cs_new_protected:Npn \keys_latexe_options_package:n #1 {
\clist_map_inline:Nn \@classoptionslist
{
\cs_if_exist:cTF
{
\c_keys_root_tl #1 /
\keys_latexe_remove_equals:n {##1} .cmd:n
}
{
\clist_put_right:Nn \keys_latexe_options_clist {##1}
\clist_remove_element:Nn \@unusedoptionlist {##1}
}
}
}
应该读
\cs_new_protected:Npn \keys_latexe_options_package:n #1 {
\clist_map_inline:Nn \@classoptionslist
{
\cs_if_exist:cT % CHANGE HERE
{
\c_keys_root_tl #1 /
\keys_latexe_remove_equals:n {##1} .cmd:n
}
{
\clist_put_right:Nn \keys_latexe_options_clist {##1}
\clist_remove_element:Nn \@unusedoptionlist {##1}
}
}
}
作为临时修复,您可以\cs_set_protected:Npn
在加载包后获得正确的定义,但如果您等待一天左右,CTAN 就会更新。