我想要的功能是:在documentclass[lang=cn]{xx}就载入ctexbook以及相应的宏包,反之lang=en就载入book以及相应的宏包,如果没写lang选项就默认加载book,也就是默认值是lang=en。最后所有documentclass[选项]里面的选项都要分别传入ctexbook或者book.
%%% autoclass.cls
\ProvidesClass{autoclass}
\DeclareKeys{% = \DeclareKeys[autoclass]
lang .choice: ,
lang/en .code:n = \def\autoclass@class{book} ,
lang/cn .code:n = \def\autoclass@class{ctexbook} ,
lang .initial:n = en ,
unknown .code:n = \autoclass@unknown ,
}
\ExplSyntaxOn
\clist_new:N \autoclass@unknownoptions
\cs_new_protected:Npn \autoclass@unknown
{
\bool_if:NTF \l__keys_no_value_bool
{ % eg. 12pt, twoside
\clist_put_right:Nx \autoclass@unknownoptions
{ \l_keys_key_str }
}
{ % eg. zihao=4, fontset=windows
\clist_put_right:Nx \autoclass@unknownoptions
{ \l_keys_key_str = { \exp_not:o \l_keys_value_tl } }
}
}
\ExplSyntaxOff
\ProcessKeyOptions % = \ProcessKeyOptions[autoclass]
\PassOptionsToClass\autoclass@unknownoptions\autoclass@class
%% 如果不需要过滤上面定义的 lang 等键,可以直接使用
%% \PassOptionsToClass\@raw@classoptionslist\autoclass@class
\LoadClass{\autoclass@class}
%%% main.tex
\documentclass[lang=cn,fontset=fandol,12pt]{autoclass}
\begin{document}
Hello.
\ifdefined\CTeX \CTeX 中文 \fi
\end{document}
感谢雾月老师,您简直就是latex之神!!跪谢!