summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/coloredtheorem/coloredtheorem.sty
blob: dd553ba75d23db53f53a994cfba805e1c7dec618 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
%% This is file `tcbtheorem.sty',
%%
%% Copyright (C) 2024 by João Lourenço <joao.lourenco@fct.unl.pt>
%%
%% This file may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.3c of this license
%% or (at your option) any later version. The latest version of this
%% license is in:
%%
%%    http://www.latex-project.org/lppl.txt
%%
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2006/05/20 or later.
%%
\NeedsTeXFormat{LaTeX2e}[2020/06/01]
\ProvidesPackage{coloredtheorem}
  [2024/03/31 v1.0 - a theorem-like environment inside a tcolobox]

\RequirePackage{tcolorbox}
\tcbuselibrary{breakable}

\gdef\tcbth{cth}

\expandafter\NewDocumentCommand\csname\tcbth newtheorem\endcsname { m m O{} }{%
  \expandafter\newcounter\expandafter{\tcbth#1}%
  \expandafter\gdef\csname\tcbth#1name\endcsname{#2}%
  \expandafter\gdef\csname\tcbth list#1name\endcsname{List of #2s}%
  \expandafter\gdef\csname#1autorefname\endcsname{#2}%
  \AtEndPreamble{%
      \ifdefined\crefname\expandafter\crefname\csname\tcbth#1\endcsname{#2}{#2s}\fi}%
  \expandafter\gdef\csname\tcbth listof#1s\endcsname
  {%
    \section*{\csname\tcbth list#1name\endcsname}%
    \expandafter\@starttoc\expandafter{lo#1}%
  }
  \expandafter\NewDocumentEnvironment\expandafter{\tcbth#1} {O{} m O{}}%
  {% \begin{tcb<SOMETHING>}
    \begin{center}%
      \ifx\relax##1\relax
        \ifx\relax##2\relax\else
          \expandafter\refstepcounter\expandafter{\tcbth#1}%
          \expandafter\addcontentsline\expandafter{lo#1}{subsection}
                        {\protect\numberline{\csname the\tcbth#1\endcsname}##2}%
        \fi
      \else
        \expandafter\addcontentsline\expandafter{lo#1}{subsection}
                        {\protect\numberline{\csname the\tcbth#1\endcsname}##1}%
      \fi
      \begin{tcolorbox}[breakable,
                        title={\textbf{\csname\tcbth#1name\endcsname
                               \ifx\relax##2\relax\else
                                   ~\csname the\tcbth#1\endcsname\fi}~~##2},
                        #3, ##3,
                       ]%
  }{% \end{tcb<SOMETHING>}
       \end{tcolorbox}%
     \end{center}%
  }%
}