9

I am using \cleveref package for which the \crefrange feature is not working for assumption environments. Can anybody tell me how I may fix this?

Here's the code:

\documentclass[12pt]{article}

\usepackage{amssymb,amsmath,latexsym,amsthm,amsfonts,mathtools}
\usepackage{hyperref}
\hypersetup{colorlinks, breaklinks, citecolor=cyan, linkcolor=cyan, urlcolor=cyan}
\usepackage[nameinlink,noabbrev,sort&compress]{cleveref}

\theoremstyle{plain}% Theorem-like structures provided by amsthm.sty
    \newtheorem{theorem}{Theorem}
    \newtheorem{lemma}{Lemma}
    \newtheorem{corollary}{Corollary}
    \newtheorem{proposition}{Proposition}
    \newtheorem{assumption}{Assumption}

    \theoremstyle{remark}
    \newtheorem{remark}{Remark}
    \newtheorem{notation}{Notation}

    \theoremstyle{definition}
    \newtheorem{definition}{Definition}
    \newtheorem{example}{Example}
    \newtheorem{problem}{Problem}

\begin{document}

\begin{theorem}\label{thm:T1}
Some theorem
\end{theorem}

\begin{theorem}\label{thm:T2}
Some other theorem
\end{theorem}

\crefrange{thm:T1}{thm:T2}

\begin{assumption}\label{asm:A1}
First Assumption
\end{assumption}

\cref{asm:A1}      


\begin{assumption}\label{asm:A2}
Second Assumption
\end{assumption}
\Cref{asm:A2}

\crefrange{asm:A1}{asm:A2}

\end{document}

Here's the output: enter image description here

1 Answer 1

7

The issue you raise is not related to \crefrange per se, nor is it related to the amsmath package. Instead, it arises because the cleveref package has not been informed, by default, how to create the plural form of the noun "assumption". Hence, macros such as \crefrange, which are programmed to use the plural forms of nouns, cannot perform their work correctly.

Consider the following, simplified version of your code. [Aside: Note that it's not necessary to load amsmath explicitly if mathtools is loaded; likewise, it's not necessary to load amsfonts explicitly if amssymb is loaded. Separately, there can be no valid reason for loading the ancient latexsym package if amssymb is loaded.] Observe that both \cref{asm:A1,asm:A2} and \crefrange{asm:A1}{asm:A2} fail to generate correct cross-referencing call-outs.

enter image description here

\documentclass[12pt]{article}
\usepackage{amssymb,amsthm,mathtools}
\usepackage[colorlinks,allcolors=cyan]{hyperref}
\usepackage[nameinlink,noabbrev]{cleveref}

\newtheorem{assumption}{Assumption}

%% Uncomment to get correct cross-referencing call-outs:
%\crefname{assumption}{assumption}{assumptions}

\begin{document}
\begin{assumption}\label{asm:A1}First\end{assumption}
\begin{assumption}\label{asm:A2}Second\end{assumption}

\Cref{asm:A1,asm:A2}      

\Crefrange{asm:A1}{asm:A2}
\end{document}

What to do? Just add the instruction

\crefname{assumption}{assumption}{assumptions}

in the preamble (after loading cleveref, naturally) and all will be well.

enter image description here


Addendum: You may well have two follow-up questions. First, which counter labels are recognized by cleveref by default, in both singular and plural form? Second, how does cleveref manage to generate singular-form cross-references to assumption environments correctly -- note that \cref{asm:A1} outputs assumption 1 rather than just ?? 1 -- even though it doesn't handle plural-form instances correctly without help from a suitable \crefname instruction?

Regarding the first question: As of September 2019, the file cleveref.sty provides the following 20 directives if the package option capitalize is not set and if the language option english (which is the default) is in force:

  \crefname@preamble{page}{page}{pages}%
  \crefname@preamble{table}{table}{tables}%
  \crefname@preamble{part}{part}{parts}%
  \crefname@preamble{chapter}{chapter}{chapters}%
  \crefname@preamble{section}{section}{sections}%
  \crefname@preamble{appendix}{appendix}{appendices}%
  \crefname@preamble{enumi}{item}{items}%
  \crefname@preamble{footnote}{footnote}{footnotes}%
  \crefname@preamble{theorem}{theorem}{theorems}%
  \crefname@preamble{lemma}{lemma}{lemmas}%
  \crefname@preamble{corollary}{corollary}{corollaries}%
  \crefname@preamble{proposition}{proposition}{propositions}%
  \crefname@preamble{definition}{definition}{definitions}%
  \crefname@preamble{result}{result}{results}%
  \crefname@preamble{example}{example}{examples}%
  \crefname@preamble{remark}{remark}{remarks}%
  \crefname@preamble{note}{note}{notes}%
  \crefname@preamble{algorithm}{algorithm}{algorithms}%
  \crefname@preamble{listing}{listing}{listings}%
  \crefname@preamble{line}{line}{lines}%

(A very similar set of directives operates if the package option capitalize is set. The default language option is english. If a suitable alternative language-related option is in force, non-English forms of the name labels will be created. As of September 2019, the available language options are, sorted alphabetically, brazilian, catalan, danish, dutch, esperanto[!], french, german and ngerman, italian, norsk, russian, spanish, swedish, and ukrainian.) Observe that singular-form and plural-form labels are predefined for the following 9 theorem-like environments: theorem, lemma, corollary, proposition, definition, result, example, remark, and note. Conversely, observe that assumption is not among these 9 environments. That's why it's necessary to provide the instruction \crefname{assumption}{assumption}{assumptions} in the preamble of your document. While you're at it, you may want to run suitable \crefname instructions for the notation and problem environments as well if you have the need to create plural-form cross-references to these environments.

On to the second question: How come that \cref{asm:A1} "works" even though, as we just confirmed, no name labels are defined by cleveref for an environment called assumption? Well, as long as the theorem-like environments (such as assumption) are defined via \newtheorem statements after both amsthm and cleveref are loaded -- an ordering strongly encouraged by cleveref, by the way -- cleveref is clever enough [pun intended] to parse the instruction

\newtheorem{assumption}{Assumption}

and treat the word "Assumption" as the singular-form label associated with the environment called assumption. Pretty nifty, in my opinion!

1
  • 1
    Thanks Mico for such insights :)
    – Scholar
    Sep 8, 2019 at 6:49

You must log in to answer this question.

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