CTeX-org / ctex-kit

Macro Packages and Scripts for Chinese TeX users
972 stars 124 forks source link

ctexbeamer 类中使用 cleveref 会产生 \H@refstepcounter 警告 #573

Closed crexyer closed 3 years ago

crexyer commented 3 years ago

ctexbeamer 类和 cleveref 宏包一起使用时,对 \H@refstepcounter 的补丁将会失败并产生警告。以下是 MWE:

\documentclass{ctexbeamer}
\usepackage{cleveref}

\begin{document}
\begin{frame}{标题}
  内容
\end{frame}
\end{document}

日志输出:

Package ctex Warning: Oops! Command `\H@refstepcounter' is NOT patchable.

cleveref.sty 有关代码:

\@ifpackageloaded{hyperref}{%
  \@ifpackagewith{hyperref}{implicit=false}{%
    \let\if@cref@hyperrefloaded\iftrue%
    \PackageWarning{cleveref}{hyperref package loaded with
      implicit=false option - disabling cleveref's hyperref support.
      This situation is not supported by cleveref, and there's no guarantee
      anything will work. You're on your own!}%
  }{%
    ...
    \def\H@refstepcounter#1{%
      \cref@old@H@refstepcounter{#1}%
      \cref@constructprefix{#1}{\cref@result}%
      \@ifundefined{cref@#1@alias}%
        {\def\@tempa{#1}}%
        {\def\@tempa{\csname cref@#1@alias\endcsname}}%
      \protected@edef\cref@currentlabel{%
        [\@tempa][\arabic{#1}][\cref@result]%
        \csname p@#1\endcsname\csname the#1\endcsname}}%
    ...
  }
}{
  ...
}

ctexbeamer.sty 有关代码

\cs_new_protected:Npn \ctex_cleveref_hook:
  {
    \@ifpackageloaded { hyperref }
      { \__ctex_cleveref_hook_aux:N \H@refstepcounter }
      {
        \__ctex_cleveref_hook_aux:N \refstepcounter@noarg
        \__ctex_cleveref_hook_aux:N \refstepcounter@optarg
      }
    \__ctex_cleveref_hook_aux:N \appendix
  }

beamer 载入 hyperref 时使用 implicit = false 选项,因此 cleveref 不会修改 \H@refstepcounter 命令,ctex 在这种情况下应该不需要对 \H@refstepcounter 进行补丁。