Tcolorbox – Restating Theorem Environment Created Using \newtcbtheorem in LaTeX

content-replicationnewtheoremtcolorboxtheoremsthmtools

The first post I saw telling me about the restatable environment: Recalling a theorem. Several questions have been asked about things like this: Making a restatable boxed theorem says to use \declaretheoremstyle; Using restatable with a custom environment is OK with using \newenvironment but messes around with counters. Neither seems very compatible with my theorem color boxes:

\newtcbtheorem[number within=section]{mylemma}{Lemma}%
{colframe=blue!45!white,enlarge top by=0.15cm,before
skip=3pt,after skip=6.5pt,fonttitle=\slshape,breakable}{lem}

Normally I can use this environment by e.g.

\begin{mylemma}{Lemma Name}{lemmalabel}
...
\end{mylemma}

(the last argument is the label). Following the example in Recalling a theorem naively, I write the following code:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\tcbuselibrary{breakable}
\usepackage[colorlinks = true, urlcolor = red]{hyperref}

\newtcbtheorem[number within=section]{mylemma}{Lemma}%
{colframe=blue!45!white,enlarge top by=0.15cm,before
skip=3pt,after skip=6.5pt,fonttitle=\slshape,breakable}{lem}

\usepackage{thmtools}
\declaretheorem[name=Theorem,numberwithin=section]{thm}

\begin{document}
\begin{mylemma}{Substitution lemma}{substitution}
Lemma in a tcolorbox
\end{mylemma}

\begin{restatable}{thm}{thmlabel}
Restatable theorem with thmtools
\end{restatable}

Theorem restated: \thmlabel*

\begin{restatable}{mylemma}{lemmalabel}
Restatable lemma in a tcolorbox
\end{restatable}

Lemma restated: \lemmalabel*

Reference to the lemma \ref{lem:substitution}
\end{document}

but this does not work (it does work if one deletes the attempt to \begin{restatable}{mylemma}...). Is it possible to tweak the restatable (and restatable*) environment to allow the following usage:

\begin{restatable}{mylemma}{Lemma Name}{lemmalabel}
...
\end{restatable}
\lemmalabel*
Lemma \ref{lem:lemmalabel}

to produce two copies of the same mylemma?



P.S. (resolved by CarLaTeX, by putting thmtools after \newtcbtheorem) while I was playing around with the package thmtools I noticed some references for my definitions were going to the wrong page (e.g. it would show Def. 2.8 and then link to Def. 1.8). I provide a MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\tcbuselibrary{breakable}
\usepackage[colorlinks = true, urlcolor = red]{hyperref}
\usepackage{thmtools}

\newtcbtheorem[number within=section]{mydef}{Definition}%
{colframe=red!65!black,enlarge top by=0.15cm,before
skip=3pt,after skip=6.5pt,fonttitle=\slshape,breakable}{def}

\begin{document}

\section*{220A Class Notes}
\section{Lecture 1}
\subsection{9/26/22 Class 2}

\begin{mydef}{Height of term}{term-height}
\end{mydef}

\begin{mydef}{Atomic formulas}{atomic-formula}
\end{mydef}

\begin{mydef}{Formulas}{formula}
\end{mydef}

\newpage

\section{Lecture 2}
\subsection{9/28/22 Class 3}

\begin{mydef}{Tarski's definition of truth/formula satisfaction}{tarski-truth}
\end{mydef}

\subsection{9/30/22 Class 4}
\begin{mydef}{Formulas as functions, notation}{formula-function-notation}
...
\end{mydef} 

\newpage
\section{Lecture 3} 

Definition \ref{def:formula-function-notation}
\end{document}

It seems to be a known issue: wrong page with pageref if using thmtools, but the fix that answer described (putting \label in a certain place) doesn't work with the \newtcbtheorem because the label is placed implicitly by tcbtheorem and not explicitly by the user's hand.

Best Answer

Try with this:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\tcbuselibrary{magazine}% also load breakable
%\tcbuselibrary{breakable}
\usepackage[colorlinks = true, urlcolor = red]{hyperref}

\newtcbtheorem[number within=section]{mylemma}{Lemma}%
{colframe=blue!45!white,enlarge top by=0.15cm,before
skip=3pt,after skip=6.5pt,fonttitle=\slshape,breakable}{lem}

\newcommand{\myrecall}[2][1]{\par\noindent\useboxarray[#2]{#1}}
\usepackage{environ}
\NewEnviron{restatlemma}[2]{%
\newboxarray{#2}%
\begin{mylemma}[reset box array=#2, store to box array=#2]{#1}{#2}
    \BODY%
\end{mylemma}%
\myrecall{#2}%
}

\usepackage{thmtools}
\declaretheorem[name=Theorem,numberwithin=section]{thm}

\begin{document}
\begin{mylemma}{Substitution lemma}{substitution}
Lemma in a tcolorbox
\end{mylemma}

\begin{restatable}{thm}{thmlabel}
Restatable theorem with thmtools
\end{restatable}

Theorem restated: \thmlabel*


\begin{restatlemma}{My Title}{lemmalabel}
Lemma stored in a tcolorbox
\end{restatlemma}

Lemma restated: \myrecall{lemmalabel}

Reference to the lemma \ref{lem:substitution}
\end{document}

enter image description here