3

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.

CarLaTeX
  • 62,716
D.R
  • 771
  • 1
    I have a same problem as yours. I also want to know how to fix it. – Sakurai.JJ Oct 05 '22 at 03:49
  • @CarLaTeX because that's what the answer in the first TeXSE post I linked recommended me to do, in order to restate a theorem. – D.R Oct 08 '22 at 07:09
  • Look at this answer: https://tex.stackexchange.com/a/348667/101651 – CarLaTeX Oct 08 '22 at 07:56
  • @CarLaTeX mmm thank you for finding this. The answers look quite fearsome... Bernard's answer is along the lines of what I'm looking for, but even then, not exactly since he sets the \label explicitly by hand, whereas mylemma doesn't do that. He also sort of explicitly puts tcolorbox stuff into \declaretheorem, and my goal is to use \newtcbtheorem command without going into the guts of it. I suppose that goal is impossible with how things are now... maybe the best option is to message the developers of thmtools directly and see if they can make it compatible with tcbtheorems. – D.R Oct 08 '22 at 08:00
  • 1
    @D.R Your problem is not simple, now I have understood, I'm looking at it but I'll also ask for some expert help in chat. Meanwhile, I'll delete my answer. – CarLaTeX Oct 08 '22 at 08:06
  • load thmtools before hyperref to avoid the duplicated destination in your second example. – Ulrike Fischer Oct 08 '22 at 08:29
  • @UlrikeFischer That is not the problem, it was already solved, see my deleted answer. – CarLaTeX Oct 08 '22 at 22:30
  • @CarLaTeX by moving in your deleted answer thmtools behind all other code you are not using thmtools at all, you could also delete it. – Ulrike Fischer Oct 08 '22 at 22:44
  • @UlrikeFischer Yes, I say it at the beginning of my answer, but it is not the OP problem – CarLaTeX Oct 08 '22 at 23:36

1 Answers1

1

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

CarLaTeX
  • 62,716
  • I think you misunderstand the point of my question. The point of my question, as indicated in the title, is about how to reconcile the restatable environment with \newtcbtheorem. I apologize if my postscript "P.S" distracted from the main question. – D.R Oct 08 '22 at 07:17
  • I already wrote out an example of how I wish the restatable environment to work with the \newtcbtheorem mylemma environment. I linked three separate TeXSE posts giving examples of how the restatable environment can be used. I can not "add an example of restated theorem" because restatable does not work with \newtcbtheorem. – D.R Oct 08 '22 at 07:21
  • I have tried to make a clearer example. – D.R Oct 08 '22 at 07:40
  • @D.R See my renewed answer, this is the best I can do. – CarLaTeX Oct 09 '22 at 07:23
  • this looks very good! I will accept the answer. Thank you for your efforts! If you want an extra challenge, this post https://tex.stackexchange.com/questions/113596/using-a-restatable-before-it-is-stated?rq=1 discusses a restatable* environment in which you are able to "[use] a restatable before it is stated". – D.R Oct 09 '22 at 07:38