通过这个最小工作示例,编译会得到一条警告:
Package 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!.
由于beamer.cls
第376
行的代码\RequirePackage[implicit=false]{hyperref}
,使用了implicit=false
选项,这个选项的作用是“完全避免使用hyperref
对外部命令(external commands)进行补丁”,而hyperref
宏包文档说正在考虑对补丁进行分类,以可以用更精细的方式控制它们。
于是,发出的这条警告就是告诉我:通过第376
行这种方式调用hyperref
,就会使得cleveref
无法正常工作。那么我的解决方法是直接更改beamer.cls
第376
行代码为\RequirePackage[implicit=true]{hyperref}
,很好,警告消失了。
但是,我并不希望直接手动更改beamer.cls
源码,因为我在另一台电脑上无法使用本地发行版,所以我希望能在最小工作示例中对beamer.cls
第376
行进行更改,这该怎么做呢?有没有什么工具可以实现?
可以缩短mwe:
\documentclass{beamer}
\usepackage{cleveref}
\begin{document}
\begin{frame}
Hello, world!
\end{frame}
\end{document}
甚至可以只是:
\documentclass{article}
\usepackage[implicit=false]{hyperref}
\usepackage{cleveref}
\begin{document}
Hello, world!
\end{document}
maybe related link:
OP的一个来源on TSE
一点小探索,一般的宏包在使用global option指定选项之后,均可以通过:\<package>setup
之类的命令实现覆盖(overwritten),但这对于hyperref
并不奏效,查看hyperref.sty
(需要pdflatex hyperref.dtx
)可以发现:
当传入impilicit=false
时,由于:
%Line2283 将其默认值设置为true
\define@key{Hyp}{implicit}[true]{%
\Hy@boolkey{implicit}{#1}%
}
同时这会触发所谓的patch external commands
% Line 4179~4203
\ifHy@implicit
\Hy@InfoNoLine{Implicit mode ON; LaTeX internals redefined}%
\else
\Hy@InfoNoLine{Implicit mode OFF; no redefinition of LaTeX internals}%
\def\MaybeStopEarly{%
\Hy@Message{Stopped early}%
\Hy@AtBeginDocument{%
\PDF@FinishDoc
\gdef\PDF@FinishDoc{}%
}%
\endinput
}%
\Hy@AtBeginDocument{%
\let\autoref\ref
\let\autopageref\pageref
\ifx\@pdfpagemode\@empty
\gdef\@pdfpagemode{UseNone}%
\fi
\global\Hy@backreffalse
}%
\Hy@AtEndOfPackage{%
\global\let\ReadBookmarks\relax
\global\let\WriteBookmarks\relax
}%
\fi
%Line 4521~4540
\ifHy@implicit
\let \T@Ref\HyRef@Ref
\def\@refstar#1{%
\NR@ref@showkeys{#1}%
\HyRef@StarSetRef{#1}\@firstoffive
}
\def\@pagerefstar#1{%
\NR@ref@showkeys{#1}%
\HyRef@StarSetRef{#1}\@secondoffive
}
\def\@namerefstar#1{%
\NR@ref@showkeys{#1}%
\HyRef@StarSetRef{#1}\@thirdoffive
}
\def\@Refstar#1{%
\NR@ref@showkeys{#1}%
\HyRef@StarSetRef{#1}\HyRef@MakeUppercaseFirstOfFive
}%
\else
\fi
且与此同时在:
% Line4204
\Hy@DisableOption{implicit}
这也解释了即使使用\hypersetup{}
在main.tex
中再次显式设置implicit
选项,也无法修改beamer.cls
中\RequirePackage[implicit=false]{hyperref}
的显式设置的原因.
我猜这种设计是因为implicit
所进行的操作均为内部patch,因此disabled了用户从外部修改implicit
的接口以防止奇怪的更改。
所以这个需求是无法实现的?
按这个道理来说,如果我依照这样的方式编写宏包模版,可以防止使用者破坏模板设置?
@u101077 (不保证对,但是如果你用类似
\Hy@DisableOption
方式禁用某些选项,那确实可以防止用户破坏/修改你的模板内部写死的选项....)我强迫症发作已经给发邮件了,但是作者没回...