![为什么 cleveref 会意外改变定理风格?](https://linux22.com/image/464398/%E4%B8%BA%E4%BB%80%E4%B9%88%20cleveref%20%E4%BC%9A%E6%84%8F%E5%A4%96%E6%94%B9%E5%8F%98%E5%AE%9A%E7%90%86%E9%A3%8E%E6%A0%BC%EF%BC%9F.png)
我观察到使用共享计数器的定理的风格在cleveref
使用时会发生意外变化。
plain
我希望所有新定理都具有像 这样的默认样式asmbook
,带有小标题字体和斜体正文字体。
然而,当cleveref
使用时,fact
与该定理共享一个计数器的定理lemma
会出乎意料地改变其风格。
我尝试通过\theoremstyle{plain}
在创建之前明确说明来修复它fact
。但是,它不起作用。然后,我创建了一个新的定理样式factstyle
并plain
在其中硬编码样式。这可以解决问题。
我注意到,如果文档类只是document
,则不存在这样的问题。我也承认hyperref
需要在之前声明cleveref
,并且所有\newtheorem
定义都必须放在cleveref
包加载之后。
这是怎么回事?cleveref
与asmbook
风格有冲突吗?
以下是重现该问题的代码和修复方法:
\documentclass[a4paper,oneside,11pt,reqno]{amsbook}
\usepackage{hyperref}
\usepackage{cleveref}
\usepackage{amsthm}
\DeclareOption*
\ProcessOptions
\theoremstyle{plain}
\newtheorem{lemma}{Lemma}
% Plain style
\newtheorem{remark}{remark}
%%%%%%
% Style Fix
% \newtheoremstyle{factstyle}% name of the style to be used
% {}% measure of space to leave above the theorem. E.g.: 3pt
% {}% measure of space to leave below the theorem. E.g.: 3pt
% {\itshape}% name of font to use in the body of the theorem
% {1.5em}% measure of space to indent
% {\scshape}% name of head font
% {.}% punctuation between head and body
% { }% space after theorem head; " " = normal interword space
% {\thmname{#1}\thmnumber{ #2}\textnormal{\thmnote{ (#3)}}}
% \theoremstyle{factstyle}
%%%%%%
% Should be Plain style but changed by cleveref?
\theoremstyle{plain}
\newtheorem{fact}[lemma]{Fact}
\begin{document}
\section{Cleveref changes theorem style unexpectedly}
\begin{lemma}
This is a lemma.
\end{lemma}
\begin{remark}
This is a remark.
\end{remark}
\begin{fact}
This is a fact.
This should look like remark however it looks differently.
When Fact shares the counter with Lemma, its style changes if cleveref is used.
To fix: Uncomment "Style Fix", or stop using cleveref.
\end{fact}
\end{document}
答案1
一般来说,amsthm
应该在 之前加载cleveref
。但是,amsbook
禁用加载amsthm
,因为它已内置。
amsbook
禁用加载的方式会产生通过测试amsthm
的结果,这取决于。混乱随之而来。amsthm
\@ifpackageloaded
cleveref
可能,cleveref
还应该对类进行测试amsart
,amsbook
这样这种冲突(可能)就不会发生。下面是一种解决方法。
\documentclass[a4paper,oneside,11pt,reqno]{amsbook}
%%% undo amsbook settings similar to amsthm
\expandafter\let\csname [email protected]\endcsname\relax
\let\theoremstyle\relax
\let\newtheoremstyle\relax
\let\pushQED\relax
\let\popQED\relax
\let\qedhere\relax
\let\mathqed\relax
\let\openbox\relax
\let\proof\relax
\let\endproof\relax
%%% now loading amsthm is possible
\usepackage{amsthm}
\usepackage{hyperref}
\usepackage{cleveref}
%%% emulate the plain theorem style of amsbook
\newtheoremstyle{amsbookplain}% name of the style to be used
{}% measure of space to leave above the theorem. E.g.: 3pt
{}% measure of space to leave below the theorem. E.g.: 3pt
{\itshape}% name of font to use in the body of the theorem
{\parindent}% measure of space to indent
{\scshape}% name of head font
{.}% punctuation between head and body
{ }% space after theorem head; " " = normal interword space
{\thmname{#1}\thmnumber{ #2}\textnormal{\thmnote{ (#3)}}}
\theoremstyle{amsbookplain}
\newtheorem{lemma}{Lemma}
\newtheorem{fact}[lemma]{Fact}
\newtheorem{remark}{remark}
%%%%%%
\begin{document}
\section{Cleveref changes theorem style unexpectedly}
\begin{lemma}
This is a lemma.
\end{lemma}
\begin{remark}
This is a remark.
\end{remark}
\begin{fact}
This is a fact.
This should look like remark however it looks differently.
When Fact shares the counter with Lemma, its style changes if cleveref is used.
To fix: Uncomment "Style Fix", or stop using cleveref.
\end{fact}
\end{document}