tcolorbox: Potential bug with duplicate label for hyperref link
hyperref
has a built-in mechanism for this. If for a counter the command \theH<counter>
is defined, then it is used for internal anchor names instead of \the<counter>
.
\documentclass{scrartcl}
\usepackage{tcolorbox}
\usepackage{hyperref}
\newtcolorbox[auto counter,number within=section]{mybox}[1][]{%
title=MyBox~\thetcbcounter,
#1
}
\providecommand{\theHtcbcounter}{\thesection.\arabic{tcbcounter}}
\begin{document}
Mybox~\ref{mybox1}; Mybox~\ref{mybox2}
\clearpage
\section{Section}
\begin{mybox}[label=mybox1]
The counter name is \texttt{\tcbcounter}.
\end{mybox}
\clearpage
\section{Section}
\begin{mybox}[label=mybox2]
The counter name is \texttt{\tcbcounter}.
\end{mybox}
\end{document}
This way the two links will have distinct anchor names and all is well.
If you want this to work with later loading of hyperref
, you have to plunge in the internals:
\makeatletter
\providecommand\theHtcb@cnt@mybox{\thesection.\arabic{tcb@cnt@mybox}}
\makeatother
because tcolorbox
associates that counter to the color box.