레이블이 다중 정의되는 것을 피하면서 재설정 가능한 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}

관련 정보