TransWikia.com

redefine theorem to be tcolorbox

TeX - LaTeX Asked on May 23, 2021

I have a large document with theoreme-like environments based on declaretheorem and references to them using label and cref.

I want to redefine those theorem-environments to be colored boxes based on tcolorbox.

Is there a simple solution without modifying the hole document?

Thank you very much.

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}

One Answer

amsthm and tcbtheorem cannot be used interchangeably, that means that your best shot to replace the one with the other is to use your editor's search and replace functionality (or sed or other nifty tricks in vim or emacs).

One thing you can do without changing our document, is using the skinning mechanism with 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}

enter image description here

Correct answer by DG' on May 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP