![将定理重新定义为 tcolorbox](https://linux22.com/image/425644/%E5%B0%86%E5%AE%9A%E7%90%86%E9%87%8D%E6%96%B0%E5%AE%9A%E4%B9%89%E4%B8%BA%20tcolorbox.png)
我有一个大型文档,其中包含基于的类似定理的环境并使用和\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
amsthm
和tcbtheorem
不能互换使用,这意味着,用另一个来替换一个的最佳方法是使用编辑器的搜索和替换功能(或或sed
中的其他巧妙技巧)。vim
emacs
你可以在不改变我们文档的情况下做一件事,那就是使用皮肤机制\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}