Skip to content

Commit

Permalink
xeCJK: 简化
Browse files Browse the repository at this point in the history
  • Loading branch information
qinglee committed Nov 20, 2016
1 parent 2432329 commit f0c9d10
Showing 1 changed file with 69 additions and 53 deletions.
122 changes: 69 additions & 53 deletions xeCJK/xeCJK.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ Copyright and Licence
% \changes{v3.3.2}{2015/05/15}{随 Unicode 7.0.0 更新简繁汉字映射。}
% \changes{v3.3.3}{2015/09/25}{更新 \hologo{LaTeX3} 代码。}
%
% \CheckSum{10167}
% \CheckSum{10153}
% \GetFileId{xeCJK.sty}
%
% \title{\bfseries\pkg{xeCJK} 宏包}
Expand Down Expand Up @@ -658,7 +658,7 @@ Copyright and Licence
%
% \begin{function}[EXP,updated=2016-11-18]{\setCJKmainfont}
% \begin{syntax}
% \tn{setCJKmainfont} \Arg{font name} \oarg{font features} 或\\
% \tn{setCJKmainfont} \Arg{font name}\oarg{font features} 或\\
% \tn{setCJKmainfont} \oarg{font features} \Arg{font name}
% \end{syntax}
% 设置正文罗马族的 CJK 字体,影响 \tn{rmfamily} 和 \tn{textrm} 的字体。后面两个
Expand All @@ -667,6 +667,9 @@ Copyright and Licence
% 找字体名见 \ref{subsubsec:fontsearch}~节;可用的字体属性选项参见
% \pkg{fontspec} 宏包的文档。需要说明的是 \pkg{xeCJK} 修改了 |AutoFakeBold|
% 和 |AutoFakeSlant| 选项,以便配合全局伪粗体和伪斜体的设定。
%
% 出于兼容性考虑,字体属性可选项可以放在字体名称前面,也可以放在后面。
% 如果可选项放在后面,字体名称与可选项之间不要有空格或者换行。
% \end{function}
%
% \begin{function}[label = ]{AutoFakeBold,AutoFakeSlant}
Expand All @@ -693,23 +696,23 @@ Copyright and Licence
%
% \begin{function}[EXP,updated=2016-11-18]{\setCJKsansfont}
% \begin{syntax}
% \tn{setCJKsansfont} \Arg{font name} \oarg{font features} 或\\
% \tn{setCJKsansfont} \Arg{font name}\oarg{font features} 或\\
% \tn{setCJKsansfont} \oarg{font features} \Arg{font name}
% \end{syntax}
% 设置正文无衬线族的 CJK 字体,影响 \tn{sffamily} 和 \tn{textsf} 的字体。
% \end{function}
%
% \begin{function}[EXP,updated=2016-11-18]{\setCJKmonofont}
% \begin{syntax}
% \tn{setCJKmonofont} \Arg{font name} \oarg{font features} 或\\
% \tn{setCJKmonofont} \Arg{font name}\oarg{font features} 或\\
% \tn{setCJKmonofont} \oarg{font features} \Arg{font name}
% \end{syntax}
% 设置正文等宽族的 CJK 字体,影响 \tn{ttfamily} 和 \tn{texttt} 的字体。
% \end{function}
%
% \begin{function}[EXP,updated=2016-11-18]{\setCJKfamilyfont}
% \begin{syntax}
% \tn{setCJKfamilyfont} \Arg{family} \Arg{font name} \oarg{font features} 或\\
% \tn{setCJKfamilyfont} \Arg{family} \Arg{font name}\oarg{font features} 或\\
% \tn{setCJKfamilyfont} \Arg{family} \oarg{font features} \Arg{font name}
% \end{syntax}
% 声明新的 CJK 字体族 \meta{family} 并指定字体。
Expand All @@ -728,12 +731,15 @@ Copyright and Licence
%
% \begin{function}[EXP,updated=2016-11-18]{\newCJKfontfamily}
% \begin{syntax}
% \tn{newCJKfontfamily} \oarg{family} \cs{\meta{font-switch}} \Arg{font name} \oarg{font features} 或\\
% \tn{newCJKfontfamily} \oarg{family} \cs{\meta{font-switch}} \Arg{font name}\oarg{font features} 或\\
% \tn{newCJKfontfamily} \oarg{family} \cs{\meta{font-switch}} \oarg{font features} \Arg{font name}
% \end{syntax}
% 声明新的 CJK 字体族 \meta{family} 并指定字体,并定义 \cs{\meta{font-switch}},在
% 文档中可以使用它来切换 CJK 字体族。可以不必指定 \meta{family},这时候 \meta{family}
% 将等于 \meta{font-switch}。事实上,\tn{newCJKfontfamily} 是 \tn{setCJKfamilyfont} 和
% 将等于 \meta{font-switch}。
% \end{function}
%
% 事实上,\tn{newCJKfontfamily} 是 \tn{setCJKfamilyfont} 和
% \tn{CJKfamily} 的合并。例如
% \begin{ctexexam}
% \newCJKfontfamily[song]\songti{SimSun}
Expand All @@ -743,11 +749,10 @@ Copyright and Licence
% \setCJKfamilyfont{song}{SimSun}
% \newcommand*{\songti}{\CJKfamily{song}}
% \end{ctexexam}
% \end{function}
%
% \begin{function}[updated=2016-11-18]{\CJKfontspec}
% \begin{syntax}
% \tn{CJKfontspec} \Arg{font name} \oarg{font features} 或\\
% \tn{CJKfontspec} \Arg{font name}\oarg{font features} 或\\
% \tn{CJKfontspec} \oarg{font features} \Arg{font name}
% \end{syntax}
% 在文档中随机定义新的 CJK 字体族,并马上使用它。
Expand Down Expand Up @@ -807,7 +812,7 @@ Copyright and Licence
%
% \begin{function}[EXP,updated=2016-11-18]{\setCJKmathfont}
% \begin{syntax}
% \tn{setCJKmathfont} \Arg{font name} \oarg{font features} 或\\
% \tn{setCJKmathfont} \Arg{font name}\oarg{font features} 或\\
% \tn{setCJKmathfont} \oarg{font features} \Arg{font name}
% \end{syntax}
% 设置数学公式中的 CJK 字体族。如果使用了 |CJKmath| 选项,但是没有使用
Expand All @@ -817,7 +822,7 @@ Copyright and Licence
%
% \begin{function}[EXP, label=, updated=2016-11-18]{\setCJKfallbackfamilyfont}
% \begin{syntax}
% \tn{setCJKfallbackfamilyfont} \Arg{family} \Arg{font name} \oarg{font features} 或\\
% \tn{setCJKfallbackfamilyfont} \Arg{family} \Arg{font name}\oarg{font features} 或\\
% \tn{setCJKfallbackfamilyfont} \Arg{family} \oarg{font features} \Arg{font name}
% \end{syntax}
% 设置 CJK 字体族 \meta{family} 的备用字体。例如,使用
Expand Down Expand Up @@ -854,8 +859,7 @@ Copyright and Licence
% \ \{\oarg{font features_1} \Arg{font name_1}\} ,
% \ \{\oarg{font features_2} \Arg{font name_2}\} ,
% \ ......
% \ \}
% \ \oarg{common font features} 或\\
% \ \}\oarg{common font features} 或\\
% \tn{setCJKfallbackfamilyfont} \Arg{family} \oarg{common font features}
% \ \{
% \ \{\oarg{font features_1} \Arg{font name_1}\} ,
Expand Down Expand Up @@ -5547,12 +5551,15 @@ Copyright and Licence
% \changes{v3.4.3}{2016/11/18}{允许字体属性可选项在后的新语法。}
% \begin{macrocode}
\NewDocumentCommand \setCJKfallbackfamilyfont { m o m }
{ \@@_pass_args:nnn { \xeCJK_set_family_fallback:xxx {#1} } {#2} {#3} }
{
\@@_pass_args:nnnn
{ \xeCJK_set_family_fallback:nnn {#1} } {#2} {#3}
{ }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\xeCJK_set_family_fallback:nnn,}
% \begin{macro}[int,aux]{\xeCJK_set_family_fallback:xxx}
% \begin{macrocode}
\cs_new_protected_nopar:Npn \xeCJK_set_family_fallback:nnn #1#2#3
{
Expand All @@ -5571,11 +5578,9 @@ Copyright and Licence
}
\group_end:
}
\cs_generate_variant:Nn \xeCJK_set_family_fallback:nnn { xxx }
\tl_new:N \l_@@_fallback_family_tl
% \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \subsection{CJK 字体族声明方式}
Expand Down Expand Up @@ -5793,9 +5798,7 @@ Copyright and Licence
\tl_new:N \l_@@_family_name_tl
\tl_new:N \l_@@_font_name_tl
\clist_new:N \l_@@_font_options_clist
\cs_generate_variant:Nn \xeCJK_set_family:nnn { Vnn , VVV , Voo }
\cs_new_protected_nopar:Npn \xeCJK_set_family:xxx #1#2#3
{ \use:x { \xeCJK_set_family:nnn {#1} {#2} {#3} } }
\cs_generate_variant:Nn \xeCJK_set_family:nnn { x , VVV , Voo }
% \end{macrocode}
% \end{macro}
%
Expand Down Expand Up @@ -6217,48 +6220,51 @@ Copyright and Licence
% \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\@@_pass_args:nnnn}
% 为了支持字体属性可选项在前在后两种语法,给出两个辅助工具,类似
% \package{fontspec} 的实现。
% \package{fontspec} 的实现。自带展开功能,额外参数 |#4| 用于后处理。
% \begin{macrocode}
\cs_new:Nn \@@_pass_args:nnn
\cs_new_protected:Npn \@@_pass_args:nnnn #1#2#3#4
{
\IfNoValueTF {#2}
{ \@@_post_arg:w {#1} {#3} }
{ #1 {#2} {#3} }
{ \@@_post_arg:w {#1} {#3} {#4} }
{
\use:x { #1 {#2} {#3} }
#4
}
}
\NewDocumentCommand \@@_post_arg:w { m m m O { } }
{
\use:x { #1 {#4} {#2} }
#3
}
\cs_generate_variant:Nn \@@_pass_args:nnn { nxx }
\NewDocumentCommand \@@_post_arg:w { m m O{} }
{ #1 {#3} {#2} }
% \end{macrocode}
%
% \end{macro}
%
% \begin{macro}{\setCJKmainfont,\setCJKsansfont,\setCJKmonofont}
% 设置文档的 CJK 普通字体、无衬线和等宽字体。
% \changes{v3.2.0}{2013/04/14}{定义中加入 \tn{normalfont}。}
% \changes{v3.4.3}{2016/11/18}{允许字体属性可选项在后的新语法。}
% \begin{macrocode}
\cs_new:Nn \@@_setmainfont:nn
{
\xeCJK_set_family:xxx { \CJKrmdefault } {#1} {#2}
\normalfont
}
\NewDocumentCommand \setCJKmainfont { o m }
{ \@@_pass_args:nnn \@@_setmainfont:nn {#1} {#2} }
\cs_new_eq:NN \setCJKromanfont \setCJKmainfont
\cs_new:Nn \@@_setsansfont:nn
{
\xeCJK_set_family:xxx { \CJKsfdefault } {#1} {#2}
\normalfont
\@@_pass_args:nnnn
{ \xeCJK_set_family:nnn { \CJKrmdefault } } {#1} {#2}
{ \normalfont }
}
\cs_new_eq:NN \setCJKromanfont \setCJKmainfont
\NewDocumentCommand \setCJKsansfont { o m }
{ \@@_pass_args:nnn \@@_setsansfont:nn {#1} {#2} }
\cs_new:Nn \@@_setmonofont:nn
{
\xeCJK_set_family:xxx { \CJKttdefault } {#1} {#2}
\normalfont
\@@_pass_args:nnnn
{ \xeCJK_set_family:nnn { \CJKsfdefault } } {#1} {#2}
{ \normalfont }
}
\NewDocumentCommand \setCJKmonofont { o m }
{ \@@_pass_args:nnn \@@_setmonofont:nn {#1} {#2} }
{
\@@_pass_args:nnnn
{ \xeCJK_set_family:nnn { \CJKttdefault } } {#1} {#2}
{ \normalfont }
}
% \end{macrocode}
% \end{macro}
%
Expand All @@ -6276,24 +6282,29 @@ Copyright and Licence
% \begin{macrocode}
\NewDocumentCommand \setCJKfamilyfont { m o m }
{
\@@_pass_args:nnn { \xeCJK_set_family:xxx {#1} } {#2} {#3}
\@@_pass_args:nnnn
{ \xeCJK_set_family:nnn {#1} } {#2} {#3}
{ }
}
\NewDocumentCommand \newCJKfontfamily { o m o m }
{
\tl_set:Nx \l_@@_tmp_tl { \IfNoValueTF {#1} { \cs_to_str:N #2 } {#1} }
\cs_new_protected_nopar:Npx #2 { \xeCJK_switch_family:n { \l_@@_tmp_tl } }
\@@_pass_args:nnn { \xeCJK_set_family:xxx { \l_@@_tmp_tl } } {#3} {#4}
\@@_pass_args:nnnn
{ \xeCJK_set_family:nnn { \l_@@_tmp_tl } } {#3} {#4}
{ }
}
\NewDocumentCommand \CJKfontspec { o m }
{
\@@_pass_args:nxx \xeCJK_fontspec:nn {#1} {#2}
\@@_pass_args:nnnn
{ \xeCJK_fontspec:nn } {#1} {#2}
{ \tex_ignorespaces:D }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}[internal]{\xeCJK_fontspec:nn}
% \begin{macrocode}
% \changes{v3.4.3}{2016/11/18}{添加 \tn{ignorespaces}。}
\cs_new_protected_nopar:Npn \xeCJK_fontspec:nn #1#2
{
\prop_get:NnNTF \g_@@_fontspec_prop
Expand All @@ -6304,7 +6315,6 @@ Copyright and Licence
{ CJKfontspec ( \int_eval:n { \g_@@_family_int + \c_one } ) }
{#1} {#2}
}
\tex_ignorespaces:D
}
\cs_new_protected_nopar:Npn \@@_fontspec:nnn #1#2#3
{
Expand Down Expand Up @@ -6435,11 +6445,13 @@ Copyright and Licence
{ LoadFandol .bool_gset:N = \g_@@_fandol_bool }
\cs_new_protected_nopar:Npn \@@_load_fandol:
{
\setCJKmainfont
[ Extension = .otf , BoldFont = FandolSong-Bold , ItalicFont = FandolKai-Regular ]
\xeCJK_set_family:xnn { \CJKrmdefault }
{ Extension = .otf , BoldFont = FandolSong-Bold , ItalicFont = FandolKai-Regular }
{ FandolSong-Regular }
\setCJKsansfont [ Extension = .otf , BoldFont = FandolHei-Bold ] { FandolHei-Regular }
\setCJKmonofont [ Extension = .otf ] { FandolFang-Regular }
\xeCJK_set_family:xnn { \CJKsfdefault }
{ Extension = .otf , BoldFont = FandolHei-Bold } { FandolHei-Regular }
\xeCJK_set_family:xnn { \CJKttdefault }
{ Extension = .otf } { FandolFang-Regular }
}
% \end{macrocode}
% \end{macro}
Expand Down Expand Up @@ -6541,7 +6553,11 @@ Copyright and Licence
% 设置 CJK 数学字体。
% \begin{macrocode}
\NewDocumentCommand \setCJKmathfont { o m }
{ \@@_pass_args:nnn { \xeCJK_set_family:xxx { \c_@@_math_tl } } {#1} {#2} }
{
\@@_pass_args:nnnn
{ \xeCJK_set_family:nnn { \c_@@_math_tl } } {#1} {#2}
{ }
}
\tl_const:Nn \c_@@_math_tl { CJKmath }
% \end{macrocode}
% \end{macro}
Expand Down

0 comments on commit f0c9d10

Please sign in to comment.