6

The below code (exluding the line \usepackage{hyperref}) provides two theorem environments thm and Thm, which use two different theorem styles (with andwithout a line break right after the theorem numbers, respectively). However, if I load hyperref (before cleveref, as the manual for the latter package tells me to do), the \crefrange on the last line breaks.

\documentclass{article}

\usepackage{ntheorem}
\usepackage{hyperref} %<--- this line breaks \crefrange
\usepackage{cleveref}

\newtheorem{thm}{Theorem}

\theoremstyle{break}
\newtheorem{Thm}[thm]{Theorem}

\crefname{thm}{theorem}{theorems}
\crefalias{Thm}{thm}

\begin{document}

    \begin{thm}\label{thm:short}
        Theorem with short text.
    \end{thm}

    \begin{Thm}[The well-ordering theorem]\label{thm:long}
        Theorem with long text.
    \end{Thm}

    \cref{thm:short}

    \cref{thm:long}

    \crefrange{thm:short}{thm:long}
\end{document} 

Without hyperref:

enter image description here

With hyperref:

enter image description here

When I insert \usepackage{hyperref}, I actually get a lot of errors the first time I compile. However, compiling the second time, this is reduced to

LaTeX Warning: References thm:short and thm:long in reference range on page 1 have different types thm and Thm on input line 27.

Can anyone find this error and (preferably) find a way to solve it?

This question relates to cleveref for theorems with same type.

  • 1
    Yes, perhaps it's better to send some information to the maintainers of both cleveref and hyperref. Heiko 'Mr. Hyperref' Oberdiek is a user here, but I am unsure about Toby Cubitt – user31729 Mar 2 '15 at 16:06
  • 1
    Toby Cubitt is a contributor to this site as well; see, e.g., his answer to the question "Crossreference in Ref Range [(1a-1e) to (1a-e)]". – Mico Mar 2 '15 at 17:57
  • @Mico: Thanks for excavation of Toby... unfortunately, he does not seem to be very active here :-( – user31729 Mar 2 '15 at 19:05
  • 1
    @IoannisFilippidis According to the cleveref manual, cleveref has to be loaded after all other reference-releated packages, including hyperref. I have not checked what happens if I change the order, and I won't because it is likely to cause other problems. By the way, Toby Cubitt has reported that he has fixed the error, so the issue will be solved in an upcoming release. – Gaussler Apr 29 '15 at 19:55
  • 1
    For the record, this is indeed fixed in recent cleveref versions. – Toby Cubitt Jun 11 '17 at 13:22
6

The cleveref package adds an optional argument to the \label command, specifying to which 'driver' counter a label should belong. Alternatively, one could use the aliascnt approach as described in the cleveref manual, see page 9 of the PDF doc.

Since this approach is not necessary if hyperref is not included, there seems to some incompatibility or a bug. My 'solution' is a workaround and not more.

\documentclass{article}

\usepackage{ntheorem}
\usepackage{hyperref} %<--- this line breaks \crefrange

\usepackage{cleveref}

\newtheorem{thm}{Theorem}

\theoremstyle{break}
\newtheorem{Thm}[thm]{Theorem}

\crefname{thm}{theorem}{theorems}
\crefalias{Thm}{thm}


\begin{document}
    \begin{thm} \label{thm:short}
        Theorem with short text.
    \end{thm}

    \begin{Thm}[The well-ordering theorem]\label[thm]{thm:long}
        Theorem with long text.
    \end{Thm}

    \cref{thm:short}

    \cref{thm:long}

    \crefrange{thm:short}{thm:long}
\end{document}

enter image description here

| improve this answer | |
  • 2
    I'd better report that bug somewhere. – Gaussler Mar 2 '15 at 15:59
4

You may have discovered a bug in cleveref's \crefalias macro and/or in hyperref. A remedy would be not to use the \crefalias device; instead, set \crefname{Thm}{theorem}{theorems} in the preamble and use \label[thm]{thm:long}, i.e., set the optional argument to \label that specifies the counter type to be used for cleveref's cross-referencing work.

enter image description here

\documentclass{article}

\usepackage{ntheorem}
\usepackage[colorlinks]{hyperref}
\usepackage[nameinlink]{cleveref}

\newtheorem{thm}{Theorem}  
\theoremstyle{break}
\newtheorem{Thm}[thm]{Theorem}

\crefname{thm}{theorem}{theorems}
\crefname{Thm}{theorem}{theorems} % new

\begin{document}    
\begin{thm}\label{thm:short}
No line break after header.
\end{thm}

\begin{Thm}[The well-ordering theorem] \label[thm]{thm:long}
Line break after header.
\end{Thm}

    \cref{thm:short}, \cref{thm:long}

    \cref{thm:short,thm:long}

    \crefrange{thm:short}{thm:long}
\end{document}
| improve this answer | |
  • 1
    It would seem there is no better solution, unfortunately. Thanks for your answer. – Gaussler Mar 2 '15 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.