为什么 cleveref 会意外改变定理风格?

为什么 cleveref 会意外改变定理风格?

我观察到使用共享计数器的定理的风格在cleveref使用时会发生意外变化。

plain我希望所有新定理都具有像 这样的默认样式asmbook,带有小标题字体和斜体正文字体。

然而,当cleveref使用时,fact与该定理共享一个计数器的定理lemma会出乎意料地改变其风格。

我尝试通过\theoremstyle{plain}在创建之前明确说明来修复它fact。但是,它不起作用。然后,我创建了一个新的定理样式factstyleplain在其中硬编码样式。这可以解决问题。

我注意到,如果文档类只是document,则不存在这样的问题。我也承认hyperref需要在之前声明cleveref,并且所有\newtheorem定义都必须放在cleveref包加载之后。

这是怎么回事?cleverefasmbook风格有冲突吗?

以下是重现该问题的代码和修复方法:

\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\@ifpackageloadedcleveref

可能,cleveref还应该对类进行测试amsartamsbook这样这种冲突(可能)就不会发生。下面是一种解决方法。

\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}

在此处输入图片描述

相关内容