5

I observe the style of a theorem that uses a shared counter being changed unexpectedly when cleveref is used.

I expect all new theorems to have the default style plain as in asmbook, with small caption title font and italic body font.

However, when cleveref is used, the fact theorem, which shares a counter with the lemma theorem, changes its style unexpectedly.

I attempt to fix it by explicitly stating \theoremstyle{plain} before creating fact. However, it does not work. Then, I create a new theorem style factstyle and hardcode the plain style in it. This can fix the issue.

I notice that if the document class is just document, there is no such issue. I also acknowledge that hyperref needs to be declared before cleveref and all \newtheorem definitions must be placed after the cleveref package is loaded.

What is going on here? Does cleveref have conflict with asmbook style?

Here are the code to reproduce the issue and the fixes:

\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
  • 1
    amsbook doesn't load amsthm, because it uses built-in styles based on it. Apparently this confuses cleveref.
    – egreg
    May 6, 2023 at 10:21

1 Answer 1

6

In general, amsthm should be loaded before cleveref. However, amsbook disables loading amsthm, because it has it built-in.

The way amsbook disables loading amsthm has the consequence that amsthm passes the \@ifpackageloaded test, which cleveref relies on. Chaos ensues.

Likely, cleveref should also have a test for the class being amsart or amsbook, so this conflict (possibly) doesn't happen. Below is a workaround.

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

enter image description here

3
  • Thanks! I found a note earlier at maths.adelaide.edu.au/anthony.roberts/LaTeX/ltxstyle.php that also mentions unloading things, but I wasn't able to comprehend it until now.
    – Michael
    May 6, 2023 at 12:34
  • If I try this workaround with the document class amsart (which is not necessary, since everything seems to work anyway), then the spaces between two environments are smaller. This confuses me, since the \theoremstyle{default} should be the same. Feb 23 at 8:14
  • @NathanaelSkrepek The hack isn't necessary with amsart, as you discovered. Why are the spaces different? The empty first two arguments are the answer: add the desired amount of space there.
    – egreg
    Feb 23 at 9:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .