Skip to content

Commit

Permalink
ctex: 兼容 cleveref
Browse files Browse the repository at this point in the history
  • Loading branch information
qinglee committed Jun 4, 2020
1 parent 012f62c commit 1ae6354
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: [push]
env:
CTAN_URL: https://mirrors.rit.edu/CTAN
TL_PACKAGES: adobemapping amsfonts amsmath atbegshi cjk cjkutils cm ctablestack currfile dvipdfmx ec epstopdf-pkg etex etoolbox euenc fancyhdr fandol filehook fontspec graphics graphics-cfg graphics-def iftex l3build l3experimental l3kernel l3packages latex-bin lm lm-math ltxcmds lualatex-math lualibs luaotfload luatex luatex85 luatexbase luatexja metafont mfware ms oberdiek platex-tools tex tex-ini-files tools trimspaces ucharcat ulem unicode-data uplatex varwidth xcolor xetex xkeyval xunicode
TL_EXTRA_PACKAGES: amscls atveryend auxhook beamer bibunits bigintcalc bitset booktabs caption cjkpunct context enumitem environ eso-pic etexcmds everyhook fontaxes footmisc geometry gettitlestring hycolor hyperref infwarerr intcalc kastrup koma-script kvdefinekeys kvoptions kvsetkeys letltxmacro mweights natbib newtx notoccite ntheorem pdfescape pdflscape pdfpages pdftexcmds pgf pkuthss psnfss refcount rerunfilecheck sansmathaccent setspace svn-prov tex-gyre tex-gyre-math thuthesis titlesec tocloft translator txfonts unicode-math uniquecounter url xecjk xits zhmetrics zhmetrics-uptex zhnumber
TL_EXTRA_PACKAGES: amscls atveryend auxhook beamer bibunits bigintcalc bitset booktabs caption cjkpunct cleveref context enumitem environ eso-pic etexcmds everyhook fontaxes footmisc geometry gettitlestring hycolor hyperref infwarerr intcalc kastrup koma-script kvdefinekeys kvoptions kvsetkeys letltxmacro mweights natbib newtx notoccite ntheorem pdfescape pdflscape pdfpages pdftexcmds pgf pkuthss psnfss refcount rerunfilecheck sansmathaccent setspace svn-prov tex-gyre tex-gyre-math thuthesis titlesec tocloft translator txfonts unicode-math uniquecounter url xecjk xits zhmetrics zhmetrics-uptex zhnumber
NOTO_URL: https://noto-website-2.storage.googleapis.com/pkgs

jobs:
Expand Down
21 changes: 19 additions & 2 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{6200}
% \CheckSum{6218}
%
% \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 @@ -8989,11 +8989,12 @@ Copyright and Licence
{
\seq_map_inline:Nn \c_@@_headings_seq
{ \ctex_fix_varioref_label:n { ##1 } }
\ctex_at_end_package:nn { cleveref } { \ctex_cleveref_hook: }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_fix_varioref_label:n}
% \begin{macro}{\ctex_fix_varioref_label:n}
% \pkg{varioref} 宏包的 \tn{labelformat} 实际上是定义一个以 |\the<#1>| 为参数的宏
% |\p@<#1>|。\LaTeX{} 在定义计数器 |<#1>| 时,都会将 |\p@<#1>| 初始化为 \tn{@empty}。
% 如果这个宏非空,说明用户自定义了标签格式,我们就不再修改。这里不能使用
Expand All @@ -9012,6 +9013,22 @@ Copyright and Licence
% \end{macrocode}
% \end{macro}
%
% \changes{v2.5.3}{2020/06/04}{兼容 \pkg{cleveref}。}
% \begin{macro}{\ctex_cleveref_hook:}
% 需要将\pkg{cleveref} 包对应命令中 |\p@|\meta{counter} 的参数及时展开,以兼容 \tn{labelformat}。
% \begin{macrocode}
\cs_new_protected:Npn \ctex_cleveref_hook:
{
\ctex_patch_cmd:Nnn \refstepcounter@noarg
{ \endcsname \csname the }
{ \expandafter \endcsname \csname the }
\ctex_patch_cmd:Nnn \refstepcounter@optarg
{ \endcsname \csname the }
{ \expandafter \endcsname \csname the }
}
% \end{macrocode}
% \end{macro}
%
% \changes{v2.5}{2020/04/19}{应用新内核中的 \tn{labelformat}。}
%
% 如果 \pkg{varioref} 已经被载入,则使用它来设置。
Expand Down
33 changes: 33 additions & 0 deletions ctex/test/testfiles/cleveref.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
\input{regression-test}

\documentclass{ctexbook}
\usepackage{cleveref}

\makeatletter
\ExplSyntaxOn
\cs_set_protected:Npn \TESTBODY
{
\seq_map_inline:Nn \c__ctex_headings_seq
{
\use:c { ##1 } { ##1 }
\TIMO
\TEST { ##1 }
{
\tl_log:N \@currentlabel
\tl_log:N \cref@currentlabel
}
\OMIT
}
}
\ExplSyntaxOff
\makeatother

\begin{document}

\START
\OMIT
\TESTBODY
\TIMO
\END

\end{document}
44 changes: 44 additions & 0 deletions ctex/test/testfiles/cleveref.pdftex.tlg
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
============================================================
TEST 1: part
============================================================
> \@currentlabel=^^e4^^b8^^80.
> \cref@currentlabel=[part][1][]^^e4^^b8^^80.
============================================================
============================================================
TEST 2: chapter
============================================================
> \@currentlabel=^^e4^^b8^^80.
> \cref@currentlabel=[chapter][1][]^^e4^^b8^^80.
============================================================
============================================================
TEST 3: section
============================================================
> \@currentlabel=1.1.
> \cref@currentlabel=[section][1][1]1.1.
============================================================
============================================================
TEST 4: subsection
============================================================
> \@currentlabel=1.1.1.
> \cref@currentlabel=[subsection][1][1,1]1.1.1.
============================================================
============================================================
TEST 5: subsubsection
============================================================
> \@currentlabel=1.1.1.
> \cref@currentlabel=[subsection][1][1,1]1.1.1.
============================================================
============================================================
TEST 6: paragraph
============================================================
> \@currentlabel=1.1.1.
> \cref@currentlabel=[subsection][1][1,1]1.1.1.
============================================================
============================================================
TEST 7: subparagraph
============================================================
> \@currentlabel=1.1.1.
> \cref@currentlabel=[subsection][1][1,1]1.1.1.
============================================================
44 changes: 44 additions & 0 deletions ctex/test/testfiles/cleveref.tlg
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
============================================================
TEST 1: part
============================================================
> \@currentlabel=一.
> \cref@currentlabel=[part][1][]一.
============================================================
============================================================
TEST 2: chapter
============================================================
> \@currentlabel=一.
> \cref@currentlabel=[chapter][1][]一.
============================================================
============================================================
TEST 3: section
============================================================
> \@currentlabel=1.1.
> \cref@currentlabel=[section][1][1]1.1.
============================================================
============================================================
TEST 4: subsection
============================================================
> \@currentlabel=1.1.1.
> \cref@currentlabel=[subsection][1][1,1]1.1.1.
============================================================
============================================================
TEST 5: subsubsection
============================================================
> \@currentlabel=1.1.1.
> \cref@currentlabel=[subsection][1][1,1]1.1.1.
============================================================
============================================================
TEST 6: paragraph
============================================================
> \@currentlabel=1.1.1.
> \cref@currentlabel=[subsection][1][1,1]1.1.1.
============================================================
============================================================
TEST 7: subparagraph
============================================================
> \@currentlabel=1.1.1.
> \cref@currentlabel=[subsection][1][1,1]1.1.1.
============================================================

0 comments on commit 1ae6354

Please sign in to comment.