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.

9
  • 1
    I have a same problem as yours. I also want to know how to fix it. Commented Oct 5, 2022 at 3: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. Commented Oct 8, 2022 at 7:09
  • Look at this answer: tex.stackexchange.com/a/348667/101651 Commented Oct 8, 2022 at 7: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. Commented Oct 8, 2022 at 8: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. Commented Oct 8, 2022 at 8:06

2 Answers 2

1

(Disclaimer: I wrote the package, keytheorems, used below.)

The keytheorems package was designed to easily integrate amsthm, tcolorbox, and restatable theorems. For your case, simply define a style and use the store key as you would for a normal theorem.

\documentclass{article} \usepackage{amsmath} \usepackage{tcolorbox} \tcbuselibrary{magazine}% also load breakable %\tcbuselibrary{breakable} \usepackage{keytheorems} \usepackage[colorlinks = true, urlcolor = red]{hyperref} \newkeytheoremstyle{tcbsty} { tcolorbox = { colframe=blue!45!white, enlarge top by=0.15cm, breakable }, bodyfont=\normalfont, headfont=\slshape, notefont=\slshape, notebraces={}{}, noteseparator={: }, headpunct={}, } \newkeytheorem{mylemma}[name=Lemma,numberwithin=section,style=tcbsty] \newkeytheorem{thm}[name=Theorem,numberwithin=section] \begin{document} \begin{mylemma}[ note=Substitution lemma, label=lem:substitution] Lemma in a tcolorbox \end{mylemma} \begin{thm}[store=thmlabel] Restatable theorem with thmtools \end{thm} Theorem restated: \getkeytheorem{thmlabel} \begin{mylemma}[ note=My Title, store=lemmalabel] Lemma stored in a tcolorbox \end{mylemma} Lemma restated: \getkeytheorem{lemmalabel} Reference to the lemma \ref{lem:substitution} \end{document} 

tcolorbox theorems

3
  • Thank you very much for your answer and for creating the new package! 1 quick question: Is there a way to change colframe without having to create a completely new newkeytheoremstyle each time? Commented Nov 25 at 23:13
  • Also, I can't seem to use use counter from for the new mylemma. I have many different tcb's, mydef, mylemma, mytheo, and currently have them all set to to use counter from=mydef Commented Nov 25 at 23:47
  • @D.R I think you should open a separate question Commented Nov 26 at 6:56
2
+50

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

5
  • 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. Commented Oct 8, 2022 at 7: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. Commented Oct 8, 2022 at 7:21
  • I have tried to make a clearer example. Commented Oct 8, 2022 at 7:40
  • @D.R See my renewed answer, this is the best I can do. Commented Oct 9, 2022 at 7:23
  • this looks very good! I will accept the answer. Thank you for your efforts! If you want an extra challenge, this post tex.stackexchange.com/questions/113596/… discusses a restatable* environment in which you are able to "[use] a restatable before it is stated". Commented Oct 9, 2022 at 7:38

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.