2

I have seen other issues about cleveref and thmtools (A problem with thmtools and cleveref, Problem with hyperref / cleveref / thmtools, How do I get rid of particular pdftex warning message?), but they are not exactly like mine.

What I have done: I use both packages in a book environment, I defined theorem and lemma (with numberline=theorem) environments using thmtool and I define one lemma in the first chapter and a second one in the second chapter. I use \ref or \cref to cite the second lemma.

What I get: I have the following warning

pdfTeX warning (ext4): destination with the same identifier (name{lemma.1}) has been already used, duplicate ignored

and in practice, the right label is showed in the pdf, but the hyperlink links with the first lemma.

Any ideas on how to fix it ?

Here's a MWE:

%!TEX encoding =UTF-8 Unicode
\documentclass{book}

%%%============== Packages
% \usepackage{fontspec}
\usepackage[utf8]{inputenc}

% Permet de gerer les accents en francais
\usepackage[T1]{fontenc}


% \usepackage{amsthm}
% \newtheorem{theorem}{Theorem}[chapter]
% \newtheorem{lemma}[theorem]{Lemma}


\usepackage{thmtools}
\declaretheorem[numberwithin=chapter,name=Theorem,
  refname={theorem,theorems},
  Refname={Theorem,Theorems}]{theorem}
\declaretheorem[numberlike=theorem,name=Lemma,
refname={lemma,lemmas},
Refname={Lemma,Lemmas}]{lemma}


% Creation de liens hypertextes (cliquables)
\usepackage{hyperref}

% Creation de liens hypertextes (cliquables)
\usepackage[capitalise,noabbrev]{cleveref}

\title{Packages clash}

\begin{document}

\chapter{First}
\section{Section 1 1}

\begin{lemma}\label{lem:1}
    Lemma 1
\end{lemma}


\chapter{Second}
\section{Section 2 1}


\begin{lemma}\label{lem:2}
    Lemma 2

\end{lemma}

\section{Section 2 2}


\ref{lem:2}


\end{document}

2

You need to execute the \declaretheorem statements after loading cleveref. Everything else about your setup is fine.

...
\usepackage{thmtools}
\usepackage{hyperref}
\usepackage[capitalise,noabbrev]{cleveref}

\declaretheorem[numberwithin=chapter,name=Theorem,
  refname={theorem,theorems},
  Refname={Theorem,Theorems}]{theorem}
\declaretheorem[numberlike=theorem,name=Lemma,
  refname={lemma,lemmas},
  Refname={Lemma,Lemmas}]{lemma}
...

Do note, though, that the capitalise option of the cleveref package will have no effect for \cref-type cross-references to theorem and lemma environments: the values set via the refname options in the \declaretheorem statements override the work of the capitalise option.

  • 1
    Good to know thank you. Actually I had another issue with using just amsthm and cleveref (it did not recognise lemma), and the solution was the same and documented in 14.1 of the documentation. May be another "non-bugs" about mathtool could be added to the section, I will ask the maintainer. – Pierre Marchand Jul 1 at 16:02
  • 1
    @PierreMarchand - Indeed, while cleveref is quite cunning at figuring out various things, it does need to have been loaded by the time \declaretheorem (in case of thmtools package) or \newtheorem (in the case of amsthm) statements are executed. Interestingly, if the ntheorem package is employed, it is not strictly necessary to have loaded cleveref before various \newtheorem directives are executed. – Mico Jul 1 at 18: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.