%%% 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}
问 如何切换不同文类?想要切换ctexbook和book