![ラベルが複数定義されるのを避けながら、再述可能な tcolorbox 定理環境を持つ方法](https://rvso.com/image/475705/%E3%83%A9%E3%83%99%E3%83%AB%E3%81%8C%E8%A4%87%E6%95%B0%E5%AE%9A%E7%BE%A9%E3%81%95%E3%82%8C%E3%82%8B%E3%81%AE%E3%82%92%E9%81%BF%E3%81%91%E3%81%AA%E3%81%8C%E3%82%89%E3%80%81%E5%86%8D%E8%BF%B0%E5%8F%AF%E8%83%BD%E3%81%AA%20tcolorbox%20%E5%AE%9A%E7%90%86%E7%92%B0%E5%A2%83%E3%82%92%E6%8C%81%E3%81%A4%E6%96%B9%E6%B3%95.png)
早い段階で定理を定義し、後でそれを証明する段階で同じ定理を再度述べたいと思う文書があります。
通常、これはパッケージを使用して行うことができます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}