Skip to content

Commit

Permalink
ctex: 兼容 luatexja 20200412.0
Browse files Browse the repository at this point in the history
fixed #493, fixed #497
  • Loading branch information
qinglee committed Apr 18, 2020
1 parent a741831 commit 5ce1dfa
Showing 1 changed file with 98 additions and 74 deletions.
172 changes: 98 additions & 74 deletions ctex/ctex.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ Copyright and Licence
% \changes{v2.4.15}{2019/03/23}{同步 \LaTeXiii{} 2019/03/05。}
%
%
% \CheckSum{5969}
% \CheckSum{5980}
%
% \CharacterTable
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
Expand Down Expand Up @@ -4280,6 +4280,7 @@ Copyright and Licence
%
% \changes{v2.0}{2014/03/08}{通过 \pkg{LuaTeX-ja} 宏包支持 \LuaLaTeX。}
% \changes{v2.3}{2015/09/25}{更新 \pkg{LuaTeX-ja} 支持(20150922.0)。}
% \changes{v2.5}{2020/04/18}{更新 \pkg{LuaTeX-ja} 支持(20200412.0)。}
%
% \pkg{LuaTeX-ja} 为了兼容 p\LaTeX 的使用习惯,对 \LaTeXe 的 \pkg{NFSS} 作了不少
% 修改和扩充,这对于简体中文用户来说不是必要的。我们在这里禁用它。
Expand All @@ -4296,13 +4297,13 @@ Copyright and Licence
%
% \begin{macrocode}
\RequirePackage { luatexja }
\@ifpackagelater { luatexja } { 2015/09/21 } { }
\@ifpackagelater { luatexja } { 2020/04/12 } { }
{ \msg_error:nnn { ctex } { package-too-old } { luatexja } }
% \end{macrocode}
%
% \begin{macrocode}
\RequirePackage { fontspec }
\@ifpackagelater { fontspec } { 2014/05/25 } { }
\@ifpackagelater { fontspec } { 2020/02/21 } { }
{ \msg_error:nnn { ctex } { package-too-old } { fontspec } }
% \end{macrocode}
%
Expand All @@ -4321,19 +4322,20 @@ Copyright and Licence
\ltjdefcharrange{1}{"80-"36F, "1E00-"1EFF}
\ltjdefcharrange{2}{"370-"4FF, "1F00-"1FFF}
\ltjdefcharrange{3}{%
"2000-"206F, "2070-"243F, "2460-"24FF, "2500-"27BF, "2900-"29FF,
"2B00-"2BFF}
"2000-"243F, "2460-"24FF, "2500-"27BF, "2900-"29FF, "2B00-"2BFF}
\ltjdefcharrange{4}{%
"500-"10FF, "1200-"1DFF, "2440-"245F, "27C0-"28FF, "2A00-"2AFF,
"2C00-"2E7F, "4DC0-"4DFF, "A4D0-"A82F, "A840-"ABFF, "FB00-"FE0F,
"FE20-"FE2F, "FE70-"FEFF, "10000-"1FFFF, "E000-"F8FF} % non-Japanese
"2C00-"2E7F, "4DC0-"4DFF, "A4D0-"A95F, "A980-"ABFF, "E000-"F8FF,
"FB00-"FE0F, "FE20-"FE2F, "FE70-"FEFF, "10000-"1AFFF, "1B170-"1F0FF,
"1F300-"1FFFF, "2000-"206F}
\ltjdefcharrange{5}{"D800-"DFFF, "E0000-"E00FF, "E01F0-"10FFFF}
\ltjdefcharrange{6}{%
"2E80-"2EFF, "3000-"30FF, "3190-"319F, "31F0-"4DBF,
"4E00-"9FFF, "F900-"FAFF, "FE10-"FE6F, "20000-"2FFFF, "E0100-"E01EF}
"4E00-"9FFF, "F900-"FAFF, "FE10-"FE1F, "FE30-"FE6F, "FF00-"FFEF,
"1B000-"1B16F, "1F100-"1F2FF, "20000-"3FFFF, "E0100-"E01EF}
\ltjdefcharrange{7}{%
"1100-"11FF, "2F00-"2FFF, "3100-"31EF, "A000-"A4CF,
"A830-"A83F, "AC00-"D7FF}
"1100-"11FF, "2F00-"2FFF, "3100-"318F, "31A0-"31EF, "A000-"A4CF,
"A960-"A97F, "AC00-"D7FF}
\ltjdefcharrange{8}{"A7, "A8, "B0, "B1, "B4, "B6, "D7, "F7}
% \end{macrocode}
% 将引号、破折号等中西文公用的标点符号归入字符范围 9,将他们设置为 JAchar。
Expand Down Expand Up @@ -4391,35 +4393,59 @@ Copyright and Licence
% \changes{v2.4.2}{2016/05/15}{恢复 \pkg{luatexja} 对 \tn{emshape} 和
% \tn{eminnershape} 的重定义。}
% \changes{v2.4.3}{2016/08/26}{简化 \pkg{fontspec} 补丁。}
% \begin{macro}[int]{\fontspec_visible_space:}
% 我们不使用 \pkg{luatexja} 对 \pkg{fontspec} 的补丁,直接处理。
% \changes{v2.5}{2020/04/18}{删除 \pkg{fontspec} 补丁。}
%
% 对 \pkg{listings} 的补丁是让代码环境支持 JAchar 类。
% \begin{macrocode}
\cs_set_protected:Npn \fontspec_visible_space:
{
\tex_iffontchar:D \tex_font:D "2423 \exp_stop_f:
\ltjalchar "2423 \exp_stop_f:
\else:
\fontspec_visible_space_fallback:
\fi:
}
\ctex_at_end_package:nn { listings }
{ \RequirePackage { lltjp-listings } }
% \end{macrocode}
% \end{macro}
%
% 对 \pkg{listings} 的补丁是让代码环境支持 JAchar 类。\pkg{LuaTeX-ja} 的补丁会将
% 代码目录标题改为日文,我们不需要。
% \paragraph{\pkg{Lua} 函数}
%
% \begin{macro}{\ctex_ltj_add_kyenc:n,\ctex_ltj_is_kenc:n,
% \ctex_ltj_patch_external_font:n}
% 直接用 |token.set_lua| 定义,不是传统意义上的 \TeX \ 宏。
% \begin{macrocode}
\ctex_at_end_package:nn { listings }
\newluafunction \g_@@_add_kyenc_func
\newluafunction \g_@@_is_kenc_func
\newluafunction \g_@@_patch_external_font_func
\group_begin:
\char_set_catcode_space:n { 32 }
\lua_now:e
{
\use:x
{
\exp_not:N \RequirePackage { lltjp-listings }
\tl_set:Nn \exp_not:N \lstlistingname
{ \exp_not:o { \lstlistingname } }
\tl_set:Nn \exp_not:N \lstlistlistingname
{ \exp_not:o { \lstlistlistingname } }
}
local t = lua.get_functions_table()
local set_lua, scan_string = token.set_lua, token.scan_string

local id = \int_value:w \g_@@_add_kyenc_func
t[id] = luatexja.jfont.add_kyenc_list
set_lua("ctex_ltj_add_kyenc:n", id, "global", "protected")

local id = \int_value:w \g_@@_is_kenc_func
t[id] = luatexja.jfont.is_kenc
set_lua("ctex_ltj_is_kenc:n", id, "global")

local id = \int_value:w \g_@@_patch_external_font_func
t[id] = function ()
local s = scan_string()
local is_braced, is_quoted
if s:sub(1,1) == '{' and s:sub(-1)=='}' then
is_braced = true; s = s:sub(2,-2)
end
if s:sub(1,1) == '"' and s:sub(-1) == '"' then
is_quoted = true; s = s:sub(2,-2)
end
s = s .. luatexja.jfont.print_aftl_address()
if is_braced then s = '{'..s..'}'
elseif is_quoted then s = '"'..s..'"'
end
tex.sprint(-2, s)
end
set_lua("ctex_ltj_patch_external_font:n", id, "global")
}
\group_end:
% \end{macrocode}
% \end{macro}
%
% \paragraph{字体切换方式}
%
Expand All @@ -4428,7 +4454,8 @@ Copyright and Licence
% \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_select_font:
{
\cs_if_exist_use:cF { \l_@@_current_font_tl }
\group_begin: \exp_args:NNc \group_end:
\cs_if_exist_use:NF { \l_@@_current_font_tl }
{ \tl_if_empty:NF \CJK@family { \@@_select_font_aux: } }
}
\tl_new:N \CJK@family
Expand Down Expand Up @@ -4463,11 +4490,15 @@ Copyright and Licence
}
\cs_new_protected:Npn \@@_push_fontname:n #1
{
\cs_gset_eq:NN \@@_save_fontname:w \font@name
\seq_gpush:No \g_@@_fontname_seq { \font@name }
\cs_gset_nopar:Npx \font@name {#1}
}
\cs_new_protected:Npn \@@_pop_fontname:
{ \cs_gset_eq:NN \font@name \@@_save_fontname:w }
{
\seq_gpop:NNT \g_@@_fontname_seq \l_@@_tmp_tl
{ \cs_gset_eq:NN \font@name \l_@@_tmp_tl }
}
\seq_new:N \g_@@_fontname_seq
% \end{macrocode}
% \end{macro}
%
Expand Down Expand Up @@ -4499,7 +4530,12 @@ Copyright and Licence
% \protected\def\globaljfont#1{%
% \afterassignment\ltj@@jfont
% \directlua{luatexja.jfont.jfontdefX(true, 'yoko','\luatexluaescapestring{\noexpand#1}')}}
% \def\ltj@@jfont{\directlua{luatexja.jfont.jfontdefY()}}
% \newluafunction\ltj@@jfont@inner
% \directlua{
% local t = lua.get_functions_table()
% t[\the\ltj@@jfont@inner] = luatexja.jfont.jfontdefY
% }
% \def\ltj@@jfont{\luafunction\ltj@@jfont@inner}
% \end{verbatim}
% \texttt{jfontdefX} 函数的作用是把 \tn{CS} 定义为其后的字体,\texttt{jfontdefY}
% 的作用是更新 \texttt{JFM} 和记录相关字体信息。最后的工作是:
Expand Down Expand Up @@ -4575,11 +4611,17 @@ Copyright and Licence
%
% \begin{macro}[int,TF]{\ctex_ltj_if_alternate_shape_exist:n}
% 即 \pkg{LuaTeX-ja} 中的 \tn{ltj@@does@alt@set},判断是否存在替代字体。
% \begin{verbatim}
% function luatexja.jfont.does_alt_set(bbase)
% aftl_base = alt_font_table_latex[bbase]
% tex.sprint(cat_lp, aftl_base and '\\@firstofone' or '\\@gobble')
% end
% \end{verbatim}
% \begin{macrocode}
\prg_new_conditional:Npnn \ctex_ltj_if_alternate_shape_exist:n #1 { T , F , TF }
{
\lua_now:e { luatexja.jfont.does_alt_set ('\lua_escape:e {#1}') }
\prg_return_true: \else: \prg_return_false: \fi:
{ \exp_after:wN \prg_return_true: \use_none:n } \prg_return_false:
}
% \end{macrocode}
% \end{macro}
Expand All @@ -4589,15 +4631,15 @@ Copyright and Licence
% \textsf{NFSS} 的替换机制定义的,它们就有相同的 \texttt{font.id}。
% |print_aftl_address| 函数的定义是
% \begin{verbatim}
% function print_aftl_address()
% tex.sprint(cat_lp, ';ltjaltfont' .. tostring(aftl_base):sub(8))
% function luatexja.jfont.print_aftl_address()
% return ';ltjaltfont' .. tostring(aftl_base):sub(8)
% end
% \end{verbatim}
% 主要目的是,如果当前字形有替代字体,则往字形的定义中加入一些标志,确保
% \texttt{font.id} 唯一。
% \begin{macrocode}
\cs_new:Npn \@@_patch_external_font:w #1 ~ at
{ #1 \lua_now:e { luatexja.jfont.print_aftl_address() } ~ at }
{ \ctex_ltj_patch_external_font:n {#1} ~ at }
% \end{macrocode}
% \end{macro}
%
Expand Down Expand Up @@ -4670,10 +4712,11 @@ Copyright and Licence
% \begin{macrocode}
\cs_new:Npn \ctex_ltj_if_jfont:nTF #1
{
\lua_now:e
{ luatexja.jfont.is_kenc( string.match('\lua_escape:e {#1}', '[^/]+') ) }
\ctex_ltj_is_kenc:n { \@@_ltj_if_jfont:w #1 / \q_stop }
\ifin@ \exp_after:wN \use_i:nn \else: \exp_after:wN \use_ii:nn \fi:
}
\cs_new:Npn \@@_ltj_if_jfont:w #1 / #2 \q_stop
{#1}
% \end{macrocode}
% \end{macro}
%
Expand All @@ -4697,7 +4740,7 @@ Copyright and Licence
% \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_get_and_define_fonts:nN #1#2
{
\ctex_ltj_if_jfont:nTF { \token_to_str:N #2 }
\exp_args:No \ctex_ltj_if_jfont:nTF { \token_to_str:N #2 }
{ \ctex_ltj_get_and_define_fonts_ja:nN }
{ \ctex_ltj_get_and_define_fonts_al:nN }
{#1} #2
Expand Down Expand Up @@ -4809,9 +4852,9 @@ Copyright and Licence
\exp_not:N \DeclareFontSubstitution
{ \CJK@encoding } { song } { \mddefault } { \shapedefault }
}
\lua_now:e { luatexja.jfont.add_kyenc_list('\CJK@encoding') }
\ctex_ltj_add_kyenc:n { \CJK@encoding }
\cs_new_protected:Npn \@@_change_encoding:
{ \tl_set_eq:NN \g_fontspec_encoding_tl \CJK@encoding }
{ \cs_set_eq:NN \g_fontspec_encoding_tl \CJK@encoding }
\DeclareFontFamily { \CJK@encoding } { song } { }
\DeclareFontShape { \CJK@encoding } { song } { \mddefault } { \shapedefault }
{ <-> psft:SimSun:cid=Adobe-GB1-5;jfm=\l_@@_jfm_tl } { }
Expand Down Expand Up @@ -5471,8 +5514,7 @@ Copyright and Licence
{
\ctex_ltj_declare_alternate_shape:nnnnnn {#1} {#2} {#3} {#4} {#5} {#6}
\ctex_ltj_set_alternate_shape:Nnnnnnn \l_@@_char_range_clist
{ \l_@@_base_family_tl } {#3} {#4}
{ \l_fontspec_family_tl } {#3} {#4}
{ \l_@@_base_family_tl } {#3} {#4} {#2} {#3} {#4}
}
% \end{macrocode}
% \end{macro}
Expand Down Expand Up @@ -6367,12 +6409,13 @@ Copyright and Licence
\char_set_catcode_space:n { 32 }
\lua_now:e
{
local id = \int_value:w \g_@@_kanjisize_func
local nulltable = { }
local t = lua.get_functions_table()
local fmt = luatexja.jfont.font_metric_table
local getattribute = tex.getattribute
local setdimen = tex.setdimen
t[\int_use:N \g_@@_kanjisize_func] = function ()
t[id] = function ()
local ft = fmt[getattribute('ltj@curjfnt')] or nulltable
local ft = ft and ft.char_type or nulltable
local fk = ft and ft[0] or nulltable
Expand Down Expand Up @@ -6963,11 +7006,8 @@ Copyright and Licence
#1 / hang .bool_set:N = \exp_not:c { CTEX@#1@hang } ,
#1 / hang .initial:n = true ,
#1 / runin .bool_set:N = \exp_not:c { CTEX@#1@runin } ,
#1 / tocline .code:n =
{
\cs_set:Npn \exp_not:c { CTEX@#1@tocline}
\exp_not:n { ####1####2 } { ####1 }
} ,
#1 / tocline .cs_set:Np = \exp_not:c { CTEX@#1@tocline}
\exp_not:n { ##1##2 } ,
\@@_plus_key_aux:nn {#1} { break } ,
%</article|book|report>
\@@_plus_key_aux:nn {#1} { format } ,
Expand Down Expand Up @@ -7166,10 +7206,6 @@ Copyright and Licence
%
% \paragraph{part 的标题}
%
% \begin{macrocode}
%<@@=>
% \end{macrocode}
%
% \changes{v2.2}{2015/06/27}{非 \cls{ctexart} 类的 \opt{part/beforeskip} 和
% \opt{part/afterskip} 选项有意义。}
%
Expand Down Expand Up @@ -7659,10 +7695,6 @@ Copyright and Licence
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
%<@@=ctex>
% \end{macrocode}
%
% \begin{macro}[int]{\CTEX@hangindent}
% 用于实现 \tn{part} 和 \tn{chapter} 标题的 \opt{indent} 和 \opt{hang} 选项。
% \begin{macrocode}
Expand Down Expand Up @@ -8526,16 +8558,12 @@ Copyright and Licence
% \end{macrocode}
%
% \begin{macrocode}
%<@@=>
% \end{macrocode}
%
% \begin{macrocode}
\keys_set:nn { ctex / section }
{
%<*article|book|report>
number = \thesection ,
aftername = \quad ,
aftertitle = \@@par ,
aftertitle = \@@@@par ,
beforeskip = 3.5ex \@plus 1ex \@minus .2ex ,
afterskip = 2.3ex \@plus .2ex ,
runin = false ,
Expand Down Expand Up @@ -8571,7 +8599,7 @@ Copyright and Licence
number = \thesubsection ,
format = \large \bfseries ,
aftername = \quad ,
aftertitle = \@@par ,
aftertitle = \@@@@par ,
beforeskip = 3.25ex \@plus 1ex \@minus .2ex ,
afterskip = 1.5ex \@plus .2ex ,
runin = false ,
Expand Down Expand Up @@ -8611,7 +8639,7 @@ Copyright and Licence
number = \thesubsubsection ,
format = \normalsize \bfseries ,
aftername = \quad ,
aftertitle = \@@par ,
aftertitle = \@@@@par ,
beforeskip = 3.25ex \@plus 1ex \@minus .2ex ,
afterskip = 1.5ex \@plus .2ex ,
runin = false ,
Expand Down Expand Up @@ -8665,7 +8693,7 @@ Copyright and Licence
{
\keys_set:nn { ctex / paragraph }
{
aftertitle = \@@par ,
aftertitle = \@@@@par ,
afterskip = 1ex \@plus .2ex ,
runin = false
}
Expand All @@ -8681,7 +8709,7 @@ Copyright and Licence
{
\keys_set:nn { ctex / subparagraph }
{
aftertitle = \@@par ,
aftertitle = \@@@@par ,
afterskip = 1ex \@plus .2ex ,
runin = false
}
Expand All @@ -8698,10 +8726,6 @@ Copyright and Licence
{ \keys_set:nn { ctex / subparagraph } { indent = \parindent } }
% \end{macrocode}
%
% \begin{macrocode}
%<@@=ctex>
% \end{macrocode}
%
% 处理附录的格式。
% \begin{macrocode}
\keys_set:nn { ctex / appendix }
Expand Down

0 comments on commit 5ce1dfa

Please sign in to comment.