ラベルが複数定義されるのを避けながら、再述可能な tcolorbox 定理環境を持つ方法

ラベルが複数定義されるのを避けながら、再述可能な tcolorbox 定理環境を持つ方法

早い段階で定理を定義し、後でそれを証明する段階で同じ定理を再度述べたいと思う文書があります。

通常、これはパッケージを使用して行うことができますthm-restate。ただし、私のドキュメントの定理ではtcolorbox環境を使用しているため、代わりにで提案されているアプローチを使用しようとしました。この答え

この方法は定理を言い直す場合には有効ですが、その場合、LaTeX はラベルが「多重定義されている」という警告を発します。このエラーのため、言い直した定理を正しく参照することはできません。

私の質問:ラベルが重複する問題に遭遇せずに、tcolorbox 定理を言い直すにはどうすればよいでしょうか?

以下に、設定と問題を示す最小限の例を示します。

\documentclass{article}

\usepackage{amsmath}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{cleveref}

\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\tcbuselibrary{magazine}
\usepackage{amsthm}

\theoremstyle{definition}

% The tcolorbox theorem
\newtcbtheorem{theorem}{Theorem}{colback=gray!10,colframe=gray!40!black}{theorem}

% Commands to restate the theorem
\newcommand{\recallthm}[2][1]{\par\noindent\useboxarray[#2]{#1}}
\usepackage{environ}
\NewEnviron{restatablethm}[2]{%
\newboxarray{#2}%
\begin{theorem}[reset box array=#2, store to box array=#2]{#1}{#2}
    \BODY%
\end{theorem}%
\recallthm{#2}%
}

% Other theorem environments might be on the same counter
\newtheorem{lemma}[tcb@cnt@theorem]{Lemma}

\begin{document}

    % The first theorem
    \begin{restatablethm}{Serious Algorithm}{coollabel}
        An example boxed theorem..
    \end{restatablethm}

    \begin{lemma}
        A simple lemma.
    \end{lemma}

    % The restated theorem
    \recallthm{coollabel}

    By \Cref{thm:collabel} we are done. % The reference here does not work (yields ??). 

\end{document}

答え1

これは [nophantom] を使用してリコール可能なボックスを作成しますが、元のボックスは作成しません。重複したハイパーターゲットに関する警告と、出荷ボックスに関する警告が生成されます。 ラベルが作成され\Crefたにもかかわらず、まったく機能しません。theorem:coollabel@cref

\documentclass{article}

\usepackage{amsmath}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{cleveref}

\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\tcbuselibrary{magazine}
\usepackage{amsthm}

\theoremstyle{definition}

% The tcolorbox theorem
\newtcbtheorem{theorem}{Theorem}{colback=gray!10,colframe=gray!40!black}{theorem}

% Commands to restate the theorem
\newcommand{\recallthm}[2][1]{\par\noindent\useboxarray[#2]{#1}}
\usepackage{environ}
\makeatletter
\NewEnviron{restatablethm}[2]{% print this copy
\newboxarray{#2}%
\begin{theorem}[reset box array=#2, store to box array=#2,nophantom]{#1}{#2}
    \BODY%
\end{theorem}%
\addtocounter{tcb@cnt@theorem}{-1}%
\begin{theorem}{#1}{#2}
    \BODY%
\end{theorem}%
%\recallthm{#2}%
}

% Other theorem environments might be on the same counter
\newtheorem{lemma}[tcb@cnt@theorem]{Lemma}

\begin{document}

    % The first theorem
    \begin{restatablethm}{Serious Algorithm}{coollabel}
        An example boxed theorem..
    \end{restatablethm}

    \begin{lemma}
        A simple lemma.
    \end{lemma}

    % The restated theorem
    \recallthm{coollabel}

    By \ref{theorem:coollabel} we are done. % The reference here does not work (yields ??). 

\end{document}

関連情報