# Correct reference but wrong hyperlinks with tcolorbox and thmtools

After spending several hours tracking down an issue with wrong hyperlinks in my thesis, I managed to cook up the following MWE:

%!TEX program = pdflatex
\documentclass{scrbook}
\usepackage{hyperref,cleveref}
\usepackage{thmtools} % <-- comment this out to fix the issue!
\usepackage{tcolorbox}
\tcbuselibrary{xparse}

\DeclareTColorBox[auto counter,number within=section,crefname={example}{examples}]{example}{ g O{} }{%
IfValueTF={#1}{title={example~\thetcbcounter\ (#1)}}{title=example~\thetcbcounter},#2
}

\begin{document}

\chapter{First chapter}
\begin{example}[label=ex:test]{My title}
Foo.
\end{example}

\chapter{Second Chapter}
\begin{example}[label=ex:test2]{My title}
Foo.
\end{example}

This was \cref{ex:test2}.
The number is right, but the hyperlink leads to \cref{ex:test}.

\end{document}


If thmtools is loaded the hyperlink to the second example is wrong, otherwise everything works as expected. This behavior seems unwanted to me, i.e. the declarations using tcolorbox should not interfere with thmtools. Additionally the fact, that the reference is right but the hyperlink wrong is very odd.

As I am not really dependent on thmtools I have no hard time disabling it, but I am interested in the reason for this behavior and wanted to report this as a possible bug.

## 1 Answer

You should simply try to load hyperref as late as possible (rule of thumb), so the order

\documentclass{scrbook}
\usepackage{thmtools}
\usepackage{hyperref}
\usepackage{cleveref}
\usepackage{tcolorbox}


will not show your problem.

A possible cause could be that thmtools.sty loads thm-autoref.sty which does some hyperlink modifications cleveref or hyperref may conflict with.

• Yes, thmtools modifies the labels – user31729 Dec 30 '17 at 21:17