1

In How to restate a theorem keeping the same number?, Thomas F. Sturm gave the perfect answer but now I find that I would like it to be "pluperfect" in that I would like to be also able to refer to the restated theorem rather than just to the original statement.

But when I insert [label={thm:1-1a}] in \begin{duplicate}{thm:1-1}{~} it compiles to the reference of the subsection in which the restated theorem is or to ?? depending on where I insert. Of course, this means that I should modify the definition of \newtcolorbox{duplicate} but I don't know how.

schremmer
  • 2,107
  • The given solution by T. F. Sturm does not have \subsection inside, but your code apparently has. Please provide the minimal working example (in this case compilable example) that has the issue you reported. The given answer does not have use a \refstepcounter for the duplicate environment, so label={thm:1-1a}] grabs the last value of \@currentlabel outside of a group, in this case originating from \subsection –  Dec 04 '17 at 18:59
  • Since the first stated theorem and and its restated version are coupled together, you apparently have to couple the references together as well, extracting the reference information from the original theorem. –  Dec 04 '17 at 19:07

1 Answers1

2

The easiest way seems to be

\newtcolorbox[auto counter,number within=chapter]%
{duplicate}%
[3][]%
{% Rest of options
}

where duplicate is an separately counted theorem. This would use a \refstepcounter macro, otherwise label= grabs the last \@currentlabel content that has been defined outside of a group, in this case from \subsection.

\documentclass{book}
    \usepackage{makeidx}
    \usepackage[hyperfootnotes=false]{hyperref}%[pdfborder={0 0 0}]
%Begin the ``quick and dirty hack'' due to Heiko Oberdiek which loads showidx
\makeatletter
\ifHy@hyperindex
  \def\HyInd@ParenLeft{(}%
% Hook in \HyInd@@wrindex
  \let\HyInd@showidx\@empty
% Hook in \HyInd@@wrindex for package showidx
  \def\HyInd@showidx#1{%
    \@showidx{#1}%
    \if@nobreak
      \ifvmode
        \nobrak
      \fi
    \fi
  }%
% Load package showidx
  \let\siOrg@makeindex\makeindex
  \let\siOrg@@index\@index
  \let\siOrg@@wrindex\@wrindex
  \let\siOrg@index\index
  \RequirePackage{showidx}
  \let\makeindex\siOrg@makeindex
  \let\@index\siOrg@@index
  \let\@wrindex\siOrg@@wrindex
  \let\index\siOrg@index
    % rest of hyperref part
  \@ifpackageloaded{multind}{%
    \let\HyInd@org@wrindex\@wrindex
    \def\@wrindex#1#2{\HyInd@@wrindex{#1}#2||\\}%
    \def\HyInd@@wrindex#1#2|#3|#4\\{%
      \ifx\\#3\\%
        \HyInd@org@wrindex{#1}{#2|hyperpage}%
      \else
        \def\Hy@temp@A{#3}%
        \ifx\Hy@temp@A\HyInd@ParenLeft
          HyInd@org@wrindex{#1}{#2|#3hyperpage}%
        \else
          \HyInd@org@wrindex{#1}{#2|#3}%
        \fi
      \fi
    }%
  }{%
    \def\@wrindex#1{\@@wrindex#1||\\}
    \def\@@wrindex#1|#2|#3\\{%
      \ifx\\#2\\%
        \protected@write\@indexfile{}{%
          \string\indexentry{#1|hyperpage}{\thepage}%
        }%
      \else
        \def\Hy@temp@A{#2}%
        \ifx\Hy@temp@A\HyInd@ParenLeft
          \protected@write\@indexfile{}{%
             \string\indexentry{#1|#2hyperpage}{\thepage}%
          }%
        \else
          \protected@write\@indexfile{}{%
            \string\indexentry{#1|#2}{\thepage}%
          }%
        \fi
      \fi
      \endgroup
      \HyInd@showidx{#1}%
      \@esphack
    }%
  }%
\fi
\makeatother
%End the ``quick and dirty hack'' due to Heiko Oberdiek which loads showidx
    \hypersetup{
                  colorlinks,
                   linkcolor={red!50!black},
                   citecolor={blue!50!black},
                  urlcolor={blue!80!black}
                }%end colors
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\newcounter{thm}%[chapter]

\usepackage{cleveref}

\newtcolorbox%
[%
use counter= thm,
number within=chapter,
number freestyle={\noexpand\thechapter.\noexpand\arabic{\tcbcounter}~\noexpand\mytitle},%
list inside= thm,%creates the list under tcblistof
list type=heorem,
crefname={Theorem}{Theorems},
Crefname={Theorem}{Theorems},
]%
{heorem}%
[2][]%
{%
detach title,%
before upper={\tcbtitle\quad},%
%breakable,%
enhanced,%
arc=0.2mm,%
%fontupper=\sffamily,
colback=green!5,%
colframe=green!35!black,%
fonttitle=\bfseries,%
coltitle=black,%
code={\gdef\mytitle{#2}},
%code={\def\mytitle{#2}},%
title=THEOREM \thetcbcounter,%
list entry={Theorem~\thetcbcounter},
#1%
}%
%Begin the Sharpe (2013-01-18) code as modified by Schulz (2016-02-1) to have math in Showindex
\let\oldopenparen\(
\let\oldcloseparen\)
\def\({\protect\oldopenparen}
\def\){\protect\oldcloseparen}
\newcommand{\INDEX}[1]{\index{#1}}
%End the Sharpe (2013-01-18) code as modified by Schulz (2016-02-1) to have math in Showindex
\newcommand*{\fullref}[1]{\hyperref[{#1}]{\cref*{#1} \nameref*{#1} \pageref*{#1}}}
%\theoremstyle{empty}%Does not work here.

\newtcolorbox[auto counter,number within=chapter]%
{duplicate}%
[3][]%
{%
detach title,%
before upper={\tcbtitle\quad},%
enhanced,%
arc=0.2mm,%
colback=green!5,%
colframe=green!35!black,%
fonttitle=\bfseries,%
coltitle=black,%
code={\gdef\mytitle{#3}},
title=THEOREM~\ref{#2},%
%list entry={Theorem~\thetcbcounter},
#1%
}%

\begin{document}
\chapter{Foo chapter}
\section{Foo section}
\subsection{Foo subsection}
\begin{heorem}[label={thm:1-1}]{~}\hspace{-4mm}
\emph{Signed addition} and \emph{signed subtraction} of the same amount undo each other.
\end{heorem}

\clearpage
\begin{duplicate}[label={thm:1-1a}]{thm:1-1}{~}
Translations of opposite amounts undo each other.
\end{duplicate}

Now see \ref{thm:1-1a}. 
\end{document}

Corrections as done in my answer here:How to display just the title of a cleveref reference to a tcolorbox?

regarding the \cref and \nameref issues...

\documentclass{book}
    \usepackage{makeidx}
    \usepackage[hyperfootnotes=false]{hyperref}%[pdfborder={0 0 0}]
%Begin the ``quick and dirty hack'' due to Heiko Oberdiek which loads showidx
\makeatletter
\ifHy@hyperindex
  \def\HyInd@ParenLeft{(}%
% Hook in \HyInd@@wrindex
  \let\HyInd@showidx\@empty
% Hook in \HyInd@@wrindex for package showidx
  \def\HyInd@showidx#1{%
    \@showidx{#1}%
    \if@nobreak
      \ifvmode
        \nobrak
      \fi
    \fi
  }%
% Load package showidx
  \let\siOrg@makeindex\makeindex
  \let\siOrg@@index\@index
  \let\siOrg@@wrindex\@wrindex
  \let\siOrg@index\index
  \RequirePackage{showidx}
  \let\makeindex\siOrg@makeindex
  \let\@index\siOrg@@index
  \let\@wrindex\siOrg@@wrindex
  \let\index\siOrg@index
    % rest of hyperref part
  \@ifpackageloaded{multind}{%
    \let\HyInd@org@wrindex\@wrindex
    \def\@wrindex#1#2{\HyInd@@wrindex{#1}#2||\\}%
    \def\HyInd@@wrindex#1#2|#3|#4\\{%
      \ifx\\#3\\%
        \HyInd@org@wrindex{#1}{#2|hyperpage}%
      \else
        \def\Hy@temp@A{#3}%
        \ifx\Hy@temp@A\HyInd@ParenLeft
          HyInd@org@wrindex{#1}{#2|#3hyperpage}%
        \else
          \HyInd@org@wrindex{#1}{#2|#3}%
        \fi
      \fi
    }%
  }{%
    \def\@wrindex#1{\@@wrindex#1||\\}
    \def\@@wrindex#1|#2|#3\\{%
      \ifx\\#2\\%
        \protected@write\@indexfile{}{%
          \string\indexentry{#1|hyperpage}{\thepage}%
        }%
      \else
        \def\Hy@temp@A{#2}%
        \ifx\Hy@temp@A\HyInd@ParenLeft
          \protected@write\@indexfile{}{%
             \string\indexentry{#1|#2hyperpage}{\thepage}%
          }%
        \else
          \protected@write\@indexfile{}{%
            \string\indexentry{#1|#2}{\thepage}%
          }%
        \fi
      \fi
      \endgroup
      \HyInd@showidx{#1}%
      \@esphack
    }%
  }%
\fi
\makeatother
%End the ``quick and dirty hack'' due to Heiko Oberdiek which loads showidx
    \hypersetup{
                  colorlinks,
                   linkcolor={red!50!black},
                   citecolor={blue!50!black},
                  urlcolor={blue!80!black}
                }%end colors
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\newcounter{thm}%[chapter]

\usepackage{cleveref}

%

\newtcolorbox%
[%
use counter= thm,
number within=chapter,
number freestyle={\noexpand\thechapter.\noexpand\arabic{\tcbcounter}~\noexpand\mytitle},%
list inside= thm,%creates the list under tcblistof
list type=heorem,
crefname={Theorem}{Theorems},
Crefname={Theorem}{Theorems},
]%
{heorem}%
[2][]%
{%
detach title,%
before upper={\tcbtitle\quad},%
%breakable,%
enhanced,%
arc=0.2mm,%
%fontupper=\sffamily,
colback=green!5,%
colframe=green!35!black,%
fonttitle=\bfseries,%
coltitle=black,%
code={\gdef\mytitle{#2}},
%code={\def\mytitle{#2}},%
title=THEOREM \thetcbcounter,%
list entry={Theorem~\thetcbcounter},
#1%
}%
%Begin the Sharpe (2013-01-18) code as modified by Schulz (2016-02-1) to have math in Showindex
\let\oldopenparen\(
\let\oldcloseparen\)
\def\({\protect\oldopenparen}
\def\){\protect\oldcloseparen}
\newcommand{\INDEX}[1]{\index{#1}}
%End the Sharpe (2013-01-18) code as modified by Schulz (2016-02-1) to have math in Showindex
\newcommand*{\fullref}[1]{\hyperref[{#1}]{\cref*{#1} \nameref*{#1} \pageref*{#1}}}
%\theoremstyle{empty}%Does not work here.

\makeatletter
\newtcolorbox[auto counter,number within=chapter,
crefname={Restated}{Restated},
]%
{duplicate}%
[3][]%
{%
detach title,%
before upper={\tcbtitle\quad},%
enhanced,%
arc=0.2mm,%
colback=green!5,%
colframe=green!35!black,%
fonttitle=\bfseries,%
coltitle=black,%
code={\gdef\mytitle{#3}\edef\@currentlabelname{THEOREM~\getrefnumber{#2}}},
title=THEOREM~\ref{#2},%
%nameref={THEOREM~\getrefnumber{#2}},
#1%
}%
\makeatother

\begin{document}
\chapter{Foo chapter}
\section{Foo section}
\subsection{Foo subsection}
\begin{heorem}[label={thm:1-1}]{~}\hspace{-4mm}
\emph{Signed addition} and \emph{signed subtraction} of the same amount undo each other.
\end{heorem}

\clearpage
\begin{duplicate}[label={thm:1-1a}]{thm:1-1}{~}
Translations of opposite amounts undo each other.
\end{duplicate}

Now see \cref{thm:1-1a} or \nameref*{thm:1-1a}. 
\end{document}
  • It works but only with \ref and not with either \nameref or \cref – schremmer Dec 04 '17 at 19:45
  • @schremmer: Well, add crefname=... to your duplicate environment, that will cure your cref problem –  Dec 04 '17 at 19:50
  • @schremmer: Actually, I answered the crefname etc. issue already here in one of your other questions: https://tex.stackexchange.com/questions/386908/how-to-display-just-the-title-of-a-cleveref-reference-to-a-tcolorbox –  Dec 04 '17 at 19:54
  • I also wonder why #3 is used as title here –  Dec 04 '17 at 19:56
  • Thanks. \cref now works but \nameref gives Foo subsection – schremmer Dec 04 '17 at 19:58
  • @schremmer: Use the nameref= option... –  Dec 04 '17 at 20:01
  • I need a bit more time to go from MWE to MagnumOpus to see what to do with named theorems. I think #3 has to do with that but I can't remember and I will have to dig into it. – schremmer Dec 04 '17 at 20:17
  • @schremmer: For example this answer here –  Jan 14 '18 at 21:35