将定理重新定义为 tcolorbox

将定理重新定义为 tcolorbox

我有一个大型文档,其中包含基于的类似定理的环境并使用和\declaretheorem对它们的引用。\label\cref

我想将这些定理环境重新定义为基于的彩色盒子tcolorbox

有没有一种简单的解决办法,不需要修改整个文档?

非常感谢。

\documentclass[11pt,a4paper,ngerman]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{amsthm}
\usepackage{thmtools}

\newtheoremstyle{break}{0pt}{0pt}{\normalfont}{0pt}{\bfseries}{}{\newline}{\thmname{#1} \thmnumber{#2} \quad \thmnote{\normalfont#3}}
\declaretheorem[style=break,name=Theorem]{theorem}

%% a colored Theorem style
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\usepackage{cleveref}

\newtcbtheorem[
number within=chapter,
crefname={Theorem}{Theoreme},
]{theoremTCB}{My Theorem}%
{colback=green!5,colframe=green!35!black,fonttitle=\bfseries}{th}

%% want to replace 'theorem' to be the colored 'theoremTCB'
%% what to do with \label  ?
%\renewenvironment{theorem}[args][default]{begdef}{enddef}

\begin{document}
\chapter{Intro}
\begin{theorem}[Optional title]
\label{myfirstTheorem}
    blabla
\end{theorem}
this is the ref: -- \cref{myfirstTheorem} --. 

The Theorem shell be redefined to look like:

\begin{theoremTCB}{Hey}{marker}
    hello
\end{theoremTCB}
this is the ref: -- \cref{th:marker} --. 

\end{document}

答案1

amsthmtcbtheorem不能互换使用,这意味着,用另一个来替换一个的最佳方法是使用编辑器的搜索和替换功能(或或sed中的其他巧妙技巧)。vimemacs

你可以在不改变我们文档的情况下做一件事,那就是使用皮肤机制\tcolorboxenvironment

\documentclass[11pt,a4paper,ngerman]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{amsthm}
\usepackage{thmtools}

\newtheoremstyle{break}{0pt}{0pt}{\normalfont}{0pt}{\bfseries}{}{\newline}{\thmname{#1} \thmnumber{#2} \quad \thmnote{\normalfont#3}}
\declaretheorem[style=break,name=Theorem]{theorem}

%% a colored Theorem style
\usepackage[most]{tcolorbox}
\tcbuselibrary{theorems}
\usepackage{cleveref}

\newtcbtheorem[
number within=chapter,
crefname={Theorem}{Theoreme},
]{theoremTCB}{My Theorem}%
{colback=green!5,colframe=green!35!black,fonttitle=\bfseries}{th}

\tcolorboxenvironment{theorem}{ 
    breakable,
    colback=green!5,
    colframe={green!35!black},
}

%% want to replace 'theorem' to be the colored 'theoremTCB'
%% what to do with \label  ?
%\renewenvironment{theorem}[args][default]{begdef}{enddef}

\begin{document}
\chapter{Intro}
\begin{theorem}[Optional title]
\label{myfirstTheorem}
    blabla
\end{theorem}
this is the ref: -- \cref{myfirstTheorem} --. 

The Theorem shell be redefined to look like:

\begin{theoremTCB}{Hey}{marker}
    hello
\end{theoremTCB}
this is the ref: -- \cref{th:marker} --. 

\end{document}

在此处输入图片描述

相关内容