Skip to content

Commit

Permalink
ctex: 放弃应用 l3cctab
Browse files Browse the repository at this point in the history
fixed #542, fixed #544

* 进一步应用 LaTeX 2020/10/01 的新钩子
  • Loading branch information
qinglee committed Oct 17, 2020
1 parent 7f2a8fa commit 182cb98
Show file tree
Hide file tree
Showing 104 changed files with 4,347 additions and 3,990 deletions.
117 changes: 77 additions & 40 deletions ctex/ctex.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ Copyright and Licence
% \changes{v2.4.15}{2019/03/23}{同步 \LaTeXiii{} 2019/03/05。}
% \changes{v2.5.1}{2020/05/02}{\pkg{zhconv} 更名为 \pkg{ctex-zhconv}。}
%
% \CheckSum{6228}
% \CheckSum{6265}
%
% \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 @@ -3423,21 +3423,49 @@ Copyright and Licence
%
% \changes{v2.5.3}{2020/06/06}{正确关闭和恢复 \LaTeXiii 语法环境。}
% \changes{v2.5.4}{2020/08/02}{应用 \pkg{l3cctab}。}
% \changes{v2.5.5}{2020/10/17}{放弃应用 \pkg{l3cctab}。}
%
% \begin{macro}[int]{\ctex_file_input:n}
% 输入文件,关闭 \LaTeXiii 语法环境,并设置 |@| 为字母类。
% 输入文件,关闭 \LaTeXiii 语法环境,并设置 |@| 为字母类、|^| 为上标和 \tn{endlinechar} 为 $13$
% \begin{macrocode}
\cs_new_protected:Npn \ctex_file_input:n #1
{
\cctab_begin:N \c_@@_package_cctab
\ctex_push_file:
\file_input:n {#1}
\cctab_end:
\ctex_pop_file:
}
\cctab_const:Nn \c_@@_package_cctab
\cs_new_protected:Npn \ctex_push_file:
{
\cctab_select:N \c_document_cctab
\seq_gpush:Nx \g_@@_file_status_seq
{
{
\bool_if:NTF \l__kernel_expl_bool
{ \ExplSyntaxOn }
{ \ExplSyntaxOff }
}
{ \char_value_catcode:n { 64 } }
{ \char_value_catcode:n { 94 } }
{ \int_use:N \tex_endlinechar:D }
}
\ExplSyntaxOff
\char_set_catcode_letter:n { 64 }
\char_set_catcode_math_superscript:n { 94 }
\int_set:Nn \tex_endlinechar:D { 13 }
}
\cs_new_protected:Npn \ctex_pop_file:
{
\seq_gpop:NN \g_@@_file_status_seq \l_@@_file_status_tl
\exp_after:wN \@@_pop_file_aux:nnnn \l_@@_file_status_tl
}
\cs_new_protected:Npn \@@_pop_file_aux:nnnn #1#2#3#4
{
#1
\char_set_catcode:nn { 64 } {#2}
\char_set_catcode:nn { 94 } {#3}
\int_set:Nn \tex_endlinechar:D {#4}
}
\tl_new:N \l_@@_file_status_tl
\seq_new:N \g_@@_file_status_seq
% \end{macrocode}
% \end{macro}
%
Expand All @@ -3447,14 +3475,14 @@ Copyright and Licence
%<*!ctexsize>
\cs_new_protected:Npn \ctex_scheme_input:n #1
{
\cctab_begin:N \c_@@_package_cctab
\ctex_push_file:
\tl_if_exist:NTF \c_@@_class_tl
{
\file_if_exist_input:nF { ctex-scheme- #1 - \c_@@_class_tl .def }
{ \file_input:n { ctex-scheme- #1 .def } }
}
{ \file_input:n { ctex-scheme- #1 .def } }
\cctab_end:
\ctex_pop_file:
}
\cs_generate_variant:Nn \ctex_scheme_input:n { o }
% \end{macrocode}
Expand Down Expand Up @@ -4105,19 +4133,25 @@ Copyright and Licence
% \tn{AtBeginShipoutFirst}。该宏对 \pdfTeX{} 和 \upTeX{} 均有用。
% \tn{AtBeginDvi} 直接将 \tn{special} 保存到盒子中,
% \tn{AtBeginShipoutFirst} 是保存到到宏中,并且不展开参数。
%
% 可以使用 \LaTeX\ 2020/10/01 的钩子机制来统一设置。
% \begin{macrocode}
%<*pdftex|uptex|aptex>
\cs_new_protected:Npn \ctex_set_zhmap:n
{ \tl_gput_right:Nx \g_@@_zhmap_tl }
\cs_new_protected:Npn \ctex_use_zhmap:
{ \tl_use:N \g_@@_zhmap_tl }
\cs_new_protected:Npn \ctex_add_dvi_zhmap:
{ \AtBeginDvi { \ctex_use_zhmap: } }
\ctex_after_end_preamble:n { \ctex_add_dvi_zhmap: }
\ctex_at_end_package:nn { atbegshi }
\cs_if_exist:NTF \ctex_gadd_ltxhook:nn
{ \ctex_gadd_ltxhook:nn { shipout/firstpage } { \ctex_use_zhmap: } }
{
\AtBeginShipoutFirst { \ctex_use_zhmap: }
\cs_gset_eq:NN \ctex_add_dvi_zhmap: \prg_do_nothing:
\cs_new_protected:Npn \ctex_add_dvi_zhmap:
{ \AtBeginDvi { \ctex_use_zhmap: } }
\ctex_after_end_preamble:n { \ctex_add_dvi_zhmap: }
\ctex_at_end_package:nn { atbegshi }
{
\AtBeginShipoutFirst { \ctex_use_zhmap: }
\cs_gset_eq:NN \ctex_add_dvi_zhmap: \prg_do_nothing:
}
}
\tl_new:N \g_@@_zhmap_tl
\@onlypreamble \ctex_set_zhmap:n
Expand Down Expand Up @@ -4246,14 +4280,10 @@ Copyright and Licence
% \begin{macrocode}
\cs_new_protected:Npn \ctex_CJK_input:n #1
{
\cctab_begin:N \c_@@_CJK_cctab
\ctex_push_file:
\int_set:Nn \tex_endlinechar:D { -1 }
\file_input:n {#1}
\cctab_end:
}
\cctab_const:Nn \c_@@_CJK_cctab
{
\cctab_select:N \c_@@_package_cctab
\int_set:Nn \tex_endlinechar:D { -1 }
\ctex_pop_file:
}
\cs_set_eq:NN \CJK@input \ctex_CJK_input:n
% \end{macrocode}
Expand Down Expand Up @@ -4390,7 +4420,7 @@ Copyright and Licence
% 宏包提供的 \tn{CJKhook} 里重新设置它,让这两个环境忽略空格的方式都受 \opt{space}
% 选项的控制。这对 \pkg{zhmCJK} 是必要的。
% \begin{macrocode}
\tl_new:N \CJKhook
\tl_if_exist:NF \CJKhook { \tl_new:N \CJKhook }
\tl_gput_right:Nn \CJKhook { \ctex_set_ignorespaces: }
% \end{macrocode}
% \end{macro}
Expand Down Expand Up @@ -4550,13 +4580,6 @@ Copyright and Licence
{ \msg_error:nnn { ctex } { package-too-old } { fontspec } }
% \end{macrocode}
%
% 引擎文件是通过 \cs{ctex_file_input:n} 载入的,其中的 \tn{catcodetable} 机制会完整恢复
% 文件载入之前的 \tn{catcode} 状态,在引擎文件中的 \tn{catcode} 设置都无效。
% 因此,对 \tn{ltjlineendcomment} 的设置要放到文件之外进行。
% \begin{macrocode}
\ctex_at_end:n { \char_set_catcode_comment:n { \ltjlineendcomment } }
% \end{macrocode}
%
% \paragraph{\pkg{LuaTeX-ja} 的默认设置}
%
% \begin{macrocode}
Expand Down Expand Up @@ -6392,6 +6415,8 @@ Copyright and Licence
%<pdftex>\reverse_if:N \if_bool:N \g_@@_zhmCJK_bool
% \end{macrocode}
%
% \changes{v2.5.5}{2020/10/17}{进一步应用 \LaTeX\ 2020/10/01 的新钩子。}
%
% \begin{macro}[int]{\ctex_provide_font_hook:NNN,\CTEX@rmfamilyhook}
% 给 \tn{rmfamily} 等字体命令加钩子,钩子名字统一为 \tn{CTEX@rmfamilyhook} 等。
% \begin{macrocode}
Expand All @@ -6400,17 +6425,27 @@ Copyright and Licence
\exp_args:Nc \@@_provide_font_hook_aux:NNNN
{ CTEX \cs_to_str:N #2 } #1#2
}
\cs_new_protected:Npn \@@_provide_font_hook_aux:NNNN #1#2#3#4
\cs_if_exist:NTF \ctex_gadd_ltxhook:nn
{
\tl_new:N #1
\cs_if_exist:NTF #3
{ \tl_gput_right:Nn #3 {#1} }
\cs_new_protected:Npn \@@_provide_font_hook_aux:NNNN #1#2#3#4
{
\tl_new:N #1
\exp_args:Nx \ctex_gadd_ltxhook:nn { \cs_to_str:N #2 } {#1}
}
}
{
\cs_new_protected:Npn \@@_provide_font_hook_aux:NNNN #1#2#3#4
{
\tl_new:N #1
\cs_if_exist:NTF #3
{ \tl_gput_right:Nn #3 {#1} }
% \end{macrocode}
% 注意此处不能用 \cs{ctex_patch_cmd:Nnn} 来打补丁,因其会关闭 \LaTeXiii 语法,
% 但 \pkg{fontspec} 会在 \tn{rmfamily} 的命令中相应加入
% \cs{l__fontspec_rmfamily_encoding_tl} 等,导致补丁失败。
% \begin{macrocode}
{ \ctex_parse_name:NN \tl_replace_once:Nnn #2 {#4} { #1#4 } }
{ \ctex_parse_name:NN \tl_replace_once:Nnn #2 {#4} { #1#4 } }
}
}
\ctex_provide_font_hook:NNN \rmfamily \@rmfamilyhook \selectfont
\ctex_provide_font_hook:NNN \sffamily \@sffamilyhook \selectfont
Expand Down Expand Up @@ -11428,12 +11463,14 @@ Copyright and Licence
% \begin{macrocode}
\@ifl@t@r \fmtversion { 2020/10/01 }
{
\cs_new_protected:Npx \ctex_at_end_preamble:n
{ \hook_gput_code:nnn { env/document/before } { \c_novalue_tl } }
\cs_new_protected:Npx \ctex_after_end_preamble:n
{ \hook_gput_code:nnn { begindocument/end } { \c_novalue_tl } }
\cs_new_protected:Npx \ctex_gadd_package_hook:nnn #1#2
{ \hook_gput_code:nnn { package/#1/#2 } { \c_novalue_tl } }
\cs_new_protected:Npx \ctex_gadd_ltxhook:nn #1
{ \hook_gput_code:nnn {#1} { \c_novalue_tl } }
\cs_new_protected:Npn \ctex_at_end_preamble:n
{ \ctex_gadd_ltxhook:nn { env/document/before } }
\cs_new_protected:Npn \ctex_after_end_preamble:n
{ \ctex_gadd_ltxhook:nn { begindocument/end } }
\cs_new_protected:Npn \ctex_gadd_package_hook:nnn #1#2
{ \ctex_gadd_ltxhook:nn { package/#1/#2 } }
\file_input_stop:
}
{ }
Expand Down
1 change: 1 addition & 0 deletions ctex/test/support/regression-test.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
\def\AUTHOR#1{\LONGTYPEOUT{Author: #1}}
\let\wlog\@gobble
2 changes: 1 addition & 1 deletion ctex/test/testfiles/backend.luatex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Don't change this file in any respect.
============================================================
TEST 1: \c_sys_backend_str
============================================================
> \c_sys_backend_str=pdfmode.
> \c_sys_backend_str=luatex.
============================================================
============================================================
TEST 2: \Gin@driver
Expand Down
4 changes: 2 additions & 2 deletions ctex/test/testfiles/basic01.luatex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Completed box being shipped out [1]
...\whatsit4=[]
...\write-{}
...\glue(\topskip) 0.72536
...\hbox(9.27464+2.27122)x345.0, glue set 257.1723fil, direction TLT
...\hbox(9.27464+2.27122)x345.0, glue set 259.80713fil, direction TLT
....\whatsit4=[]
....\localpar
.....\localinterlinepenalty=0
Expand Down Expand Up @@ -54,7 +54,7 @@ Completed box being shipped out [1]
....\kern-1.31741
....\TU/lmr/m/n/10.53937 X
....\penalty 10000
....\glue 2.63484 plus 1.0 minus 1.0
....\glue 0.0
....\hbox(9.27464+1.26472)x5.26968, direction TLT
.....\LTJY3/FandolSong-Regular(0)/m/n/10.53937 !
....\penalty 10000
Expand Down
41 changes: 22 additions & 19 deletions ctex/test/testfiles/basic01.pdftex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,30 @@ Author: Xiangdong Zeng
TEST 1: Basic text
============================================================
LaTeX Font Info: Trying to load font information for C70+rm on input line ....
)
(c70rm.fd)
Package CJKpunct Info: use punctuation spaces for family 'rm' with punctstyle (quanjiao) on input line ....
(ctex-zhmap-fandol.tex)
Completed box being shipped out [1]
\vbox(633.0+0.0)x407.0
.\special{pdf:mapline gbk@UGBK@ UniGB-UTF16-H FandolSong-Regular.otf}
.\special{pdf:mapline gbksong@UGBK@ UniGB-UTF16-H FandolSong-Regular.otf}
.\special{pdf:mapline gbkkai@UGBK@ UniGB-UTF16-H FandolKai-Regular.otf}
.\special{pdf:mapline gbkhei@UGBK@ UniGB-UTF16-H FandolHei-Regular.otf}
.\special{pdf:mapline gbkfs@UGBK@ UniGB-UTF16-H FandolFang-Regular.otf}
.\special{pdf:mapline cyberb@Unicode@ UniGB-UTF16-H FandolSong-Regular.otf}
.\special{pdf:mapline unisong@Unicode@ UniGB-UTF16-H FandolSong-Regular.otf}
.\special{pdf:mapline unikai@Unicode@ UniGB-UTF16-H FandolKai-Regular.otf}
.\special{pdf:mapline unihei@Unicode@ UniGB-UTF16-H FandolHei-Regular.otf}
.\special{pdf:mapline unifs@Unicode@ UniGB-UTF16-H FandolFang-Regular.otf}
.\special{pdf:mapline gbksongsl@UGBK@ UniGB-UTF16-H FandolSong-Regular.otf -s .\ETC.}
.\special{pdf:mapline gbkkaisl@UGBK@ UniGB-UTF16-H FandolKai-Regular.otf -s .16\ETC.}
.\special{pdf:mapline gbkheisl@UGBK@ UniGB-UTF16-H FandolHei-Regular.otf -s .16\ETC.}
.\special{pdf:mapline gbkfssl@UGBK@ UniGB-UTF16-H FandolFang-Regular.otf -s .16\ETC.}
.\special{pdf:mapline unisongsl@Unicode@ UniGB-UTF16-H FandolSong-Regular.otf -\ETC.}
.\special{pdf:mapline unikaisl@Unicode@ UniGB-UTF16-H FandolKai-Regular.otf -s \ETC.}
.\special{pdf:mapline uniheisl@Unicode@ UniGB-UTF16-H FandolHei-Regular.otf -s \ETC.}
.\special{pdf:mapline unifssl@Unicode@ UniGB-UTF16-H FandolFang-Regular.otf -s \ETC.}
.\hbox(0.0+0.0)x0.0
..\special{pdf:mapline gbk@UGBK@ UniGB-UTF16-H FandolSong-Regular.otf}
..\special{pdf:mapline gbksong@UGBK@ UniGB-UTF16-H FandolSong-Regular.otf}
..\special{pdf:mapline gbkkai@UGBK@ UniGB-UTF16-H FandolKai-Regular.otf}
..\special{pdf:mapline gbkhei@UGBK@ UniGB-UTF16-H FandolHei-Regular.otf}
..\special{pdf:mapline gbkfs@UGBK@ UniGB-UTF16-H FandolFang-Regular.otf}
..\special{pdf:mapline cyberb@Unicode@ UniGB-UTF16-H FandolSong-Regular.otf}
..\special{pdf:mapline unisong@Unicode@ UniGB-UTF16-H FandolSong-Regular.otf}
..\special{pdf:mapline unikai@Unicode@ UniGB-UTF16-H FandolKai-Regular.otf}
..\special{pdf:mapline unihei@Unicode@ UniGB-UTF16-H FandolHei-Regular.otf}
..\special{pdf:mapline unifs@Unicode@ UniGB-UTF16-H FandolFang-Regular.otf}
..\special{pdf:mapline gbksongsl@UGBK@ UniGB-UTF16-H FandolSong-Regular.otf -s .\ETC.}
..\special{pdf:mapline gbkkaisl@UGBK@ UniGB-UTF16-H FandolKai-Regular.otf -s .16\ETC.}
..\special{pdf:mapline gbkheisl@UGBK@ UniGB-UTF16-H FandolHei-Regular.otf -s .16\ETC.}
..\special{pdf:mapline gbkfssl@UGBK@ UniGB-UTF16-H FandolFang-Regular.otf -s .16\ETC.}
..\special{pdf:mapline unisongsl@Unicode@ UniGB-UTF16-H FandolSong-Regular.otf -\ETC.}
..\special{pdf:mapline unikaisl@Unicode@ UniGB-UTF16-H FandolKai-Regular.otf -s \ETC.}
..\special{pdf:mapline uniheisl@Unicode@ UniGB-UTF16-H FandolHei-Regular.otf -s \ETC.}
..\special{pdf:mapline unifssl@Unicode@ UniGB-UTF16-H FandolFang-Regular.otf -s \ETC.}
.\glue 16.0
.\vbox(617.0+0.0)x345.0, shifted 62.0
..\vbox(12.0+0.0)x345.0, glue set 5.20798fil
Expand Down Expand Up @@ -78,6 +80,7 @@ Completed box being shipped out [1]
...\glue 0.0 plus 0.0001fil
..\glue(\baselineskip) 30.0
..\hbox(0.0+0.0)x345.0
.\kern 0.0
============================================================
============================================================
TEST 2: Muliple paragraphs
Expand Down
29 changes: 15 additions & 14 deletions ctex/test/testfiles/basic01.uptex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ LaTeX Font Warning: Font shape `JY2/zhrm/m/sl' undefined
(Font) using `JY2/zhrm/m/it' instead on input line ....
Completed box being shipped out [1]
\vbox(633.0+0.0)x407.0
.\special{pdf:mapline upserif-h UniGB-UTF16-H FandolSong-Regular.otf}
.\special{pdf:mapline upserif-v UniGB-UTF16-V FandolSong-Regular.otf}
.\special{pdf:mapline upserifb-h UniGB-UTF16-H FandolSong-Bold.otf}
.\special{pdf:mapline upserifb-v UniGB-UTF16-V FandolSong-Bold.otf}
.\special{pdf:mapline upserifit-h UniGB-UTF16-H FandolKai-Regular.otf}
.\special{pdf:mapline upserifit-v UniGB-UTF16-V FandolKai-Regular.otf}
.\special{pdf:mapline upsans-h UniGB-UTF16-H FandolHei-Regular.otf}
.\special{pdf:mapline upsans-v UniGB-UTF16-V FandolHei-Regular.otf}
.\special{pdf:mapline upsansb-h UniGB-UTF16-H FandolHei-Bold.otf}
.\special{pdf:mapline upsansb-v UniGB-UTF16-V FandolHei-Bold.otf}
.\special{pdf:mapline upmono-h UniGB-UTF16-H FandolFang-Regular.otf}
.\special{pdf:mapline upmono-v UniGB-UTF16-V FandolFang-Regular.otf}
.\hbox(0.0+0.0)x0.0
..\special{pdf:mapline upserif-h UniGB-UTF16-H FandolSong-Regular.otf}
..\special{pdf:mapline upserif-v UniGB-UTF16-V FandolSong-Regular.otf}
..\special{pdf:mapline upserifb-h UniGB-UTF16-H FandolSong-Bold.otf}
..\special{pdf:mapline upserifb-v UniGB-UTF16-V FandolSong-Bold.otf}
..\special{pdf:mapline upserifit-h UniGB-UTF16-H FandolKai-Regular.otf}
..\special{pdf:mapline upserifit-v UniGB-UTF16-V FandolKai-Regular.otf}
..\special{pdf:mapline upsans-h UniGB-UTF16-H FandolHei-Regular.otf}
..\special{pdf:mapline upsans-v UniGB-UTF16-V FandolHei-Regular.otf}
..\special{pdf:mapline upsansb-h UniGB-UTF16-H FandolHei-Bold.otf}
..\special{pdf:mapline upsansb-v UniGB-UTF16-V FandolHei-Bold.otf}
..\special{pdf:mapline upmono-h UniGB-UTF16-H FandolFang-Regular.otf}
..\special{pdf:mapline upmono-v UniGB-UTF16-V FandolFang-Regular.otf}
.\glue 16.0
.\vbox(617.0+0.0)x345.0, shifted 62.0
..\vbox(12.0+0.0)x345.0, glue set 5.20798fil
Expand All @@ -32,7 +33,7 @@ Completed box being shipped out [1]
..\vbox(550.0+0.0)x345.0, glue set 539.94232fil
...\write-{}
...\glue(\topskip) 0.72536
...\hbox(9.27464+2.26889)x345.0, glue set 251.90254fil
...\hbox(9.27464+2.26889)x345.0, glue set 254.53738fil
....\hbox(0.0+0.0)x21.07874
....\JY2/zhrm/m/n/10.53937 你
....\JY2/zhrm/m/n/10.53937 好
Expand All @@ -48,7 +49,6 @@ Completed box being shipped out [1]
....\kern -1.31741
....\OT1/cmr/m/n/10.53937 X
....\penalty 10000(for kinsoku)
....\glue(\xkanjiskip) 2.63484 plus 1.0 minus 1.0
....\JY2/zhrm/m/n/10.53937 !
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
Expand All @@ -59,6 +59,7 @@ Completed box being shipped out [1]
...\glue 0.0 plus 0.0001fil
..\glue(\baselineskip) 30.0
..\hbox(0.0+0.0)x345.0
.\kern 0.0
============================================================
============================================================
TEST 2: Muliple paragraphs
Expand Down
4 changes: 2 additions & 2 deletions ctex/test/testfiles/basic02.luatex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Completed box being shipped out [1]
...\whatsit4=[]
...\write-{}
...\glue(\topskip) 1.2
...\hbox(8.8+2.155)x345.0, glue set 266.66702fil, direction TLT
...\hbox(8.8+2.155)x345.0, glue set 269.16702fil, direction TLT
....\whatsit4=[]
....\localpar
.....\localinterlinepenalty=0
Expand Down Expand Up @@ -49,7 +49,7 @@ Completed box being shipped out [1]
....\kern-1.25
....\TU/lmr/m/n/10 X
....\penalty 10000
....\glue 2.5 plus 1.0 minus 1.0
....\glue 0.0
....\hbox(8.8+1.2)x5.0, direction TLT
.....\LTJY3/FandolSong-Regular(0)/m/n/10 !
....\penalty 10000
Expand Down
Loading

0 comments on commit 182cb98

Please sign in to comment.