Only the first numbered environment created with tcolorbox
gets an <a>
tag destination in the HTML when converted with htlatex
. Consider the following MWE:
\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{cleveref}
\newtcbtheorem{theorem}{}{}{th}
\crefname{tcb@cnt@theorem}{theorem}{theorems}
\begin{document}
\begin{theorem}{}{1}
Text
\end{theorem}
\begin{theorem}{}{2}
Text
\end{theorem}
\end{document}
This results in the following HTML:
<div class="tcolorbox theorem" id="tcolobox-1">
<a id="x1-1doc"></a>
<div class="tcolorbox-title">...</div>
<div class="tcolorbox-content">...</div>
</div>
<div class="tcolorbox theorem" id="tcolobox-2">
<div class="tcolorbox-title">...</div>
<div class="tcolorbox-content">...</div>
</div>
Here, only the first theorem got the <a id="x1-1doc"></a>
tag. Cross references to the theorems, \cref{th:1}
and \cref{th:2}
, yield "theorem 1" and "theorem 2", but both link to the first one: <a href="#x1-1doc">
. Moreover, a plain \ref{th:1}
does not produce any output.
Is there a way to give every instance of theorem
a unique <a>
tag destination? Moreover, this should also work for other environments defined via tcolorbox
. Lastly, is there a way to get \ref
to work for these environments?
UPDATE
michal.h21 posted a solution that ensures that every environment has a unique link destination. This works fine if the document only uses one type of environment defined via tcolorbox
. However, consider the following example:
\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{cleveref}
\newtcbtheorem{theorem}{Theorem}{}{th}
\newtcbtheorem{lemma}{Lemma}{}{lem}
\crefname{tcb@cnt@theorem}{theorem}{theorems}
\crefname{tcb@cnt@lemma}{lemma}{lemmas}
\begin{document}
\begin{theorem}{}{1}
Text
\end{theorem}
\begin{theorem}{}{2}
Text
\end{theorem}
\begin{lemma}{}{}
Text
\end{lemma}
See \cref{th:1} and \cref{th:2}.
\end{document}
This renders as
Here the last reference is incorrectly printed as "lemma 1" instead of "theorem 2". How can this be fixed?