summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/coloredtheorem/coloredtheorem-doc.tex
blob: 55ae3d3ae5cd405c222313ad525d305bf54ef028 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
\documentclass{article}

\usepackage[margin=1.6in]{geometry}
\usepackage{fancyvrb}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% AMSMATH stuff
% \usepackage{amsthm}
% \usepackage{thmtools}
% \usepackage{amsfonts}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TCBTHEOREM stuff
\usepackage{coloredtheorem}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXAMPLE document
\usepackage{amsfonts}
\usepackage{kantlipsum}
\usepackage{tabularx}
\usepackage{xspace}
\newcommand\tcthrm{\texttt{coloredtheorem}\xspace}

%% ALGPSEUDOCODEX stuff
\usepackage{algorithm}
\usepackage[
  noEnd=false,
  beginComment={$\triangleright$~\scriptsize},
  beginLComment={$\triangleright$~},
  endLComment={},
]{algpseudocodex}

\algnewcommand\Input{\textbf{Input:~}}
\algrenewcommand\Output{\textbf{Output:~}}
\algrenewcommand\algorithmicforall{\textbf{for each}}
\algnewcommand\Vspace{% 
  {\setlength\itemsep{-1ex}\item[]~}
}
\algnewcommand\Let[2]{\State \ensuremath{#1 \gets #2}}
\algnewcommand\And{\ensuremath{\wedge}\xspace}
\algnewcommand\Or{\ensuremath{\vee}\xspace}
\algnewcommand\Not{\ensuremath{\neg}\xspace}

\usepackage[colorlinks,linkcolor=blue!80]{hyperref}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% MAIN DOCUMENT
\begin{document}
  \title{The \tcthrm package}
  \author{João M. Lourenço\\\texttt{\small joao.lourenco@fct.unl.pt}}
  \date{March 31, 2024}
  
  \maketitle
  

\section{Introduction}
\label{sec:introduction}

The \tcthrm package is a simple environment, which takes no options, and that allows to write stuff inside boxes from \texttt{tcolorbox}.  So, this packages includes \texttt{tcolorbox} if necessary. You may include \texttt{tcolorbox} with your own favourite options prior to including this package.

Akin to \verb!\newtheorem! from the \verb!amsmath! package, the user should start by defining a new \emph{theorem/box} group and customize its aspect. Each new environment will have its own counter/numbering. Notice that \verb!\label{…}! and \verb!\ref{…}! work as expected.  The is also a command to generate the corresponding \emph{list of …}

\section{Usage}
\label{sec:usage}

\begin{description}
  \item[]{\bfseries\verb+\usepackage{coloredtheorem}+}
  \begin{description}
      \item[]Load the \texttt{coloredtheorem} package.  This package will load \texttt{tcolorbox} if necessary.
  \end{description}
  \item[]{\bfseries\Verb[commandchars=!()]+\!tcbth()newtheorem{<envname>}{<Name>}[<tcolorbox options>]+}
  \begin{description}
      \item[]\verb+<envname>+ is the environment name, e.g., \verb!theorem!.
      \item[]\verb+<Name>+ is the name for new environment being defined, e.g., \emph{Theorem}.
      \item[]\verb+<tcolorbox options>+ options to be passed to the \verb+tcolorbox+ environment to customize the boxes for the given environment (this argument is optional).
  \end{description}
  \item[]{\bfseries\Verb[commandchars=!()]+\begin{!tcbth()<envname>}{<Caption>}[<tcolorbox options>]<Contents>\end{!tcbth()<envname>}+}
  \begin{description}
    \item[]\verb+<envname>+ is the environment name, e.g., \verb+theorem+.
    \item[]\verb+<Caption>+ is the caption/title of the box.
    \item[]\verb+<tcolorbox options>+ options to be passed to the \verb+tcolobox+ environment, which will override the defaults given in \verb+\cthnewtheorem+.
    \item[]\verb+<Contents>+ the contents to by typeset inside the coulored environment.
  \end{description}
  \item[]{\bfseries\Verb[commandchars=!()]+\!tcbth()listof<envname>s+}
  \begin{description}
      \item[]\verb+<envname>+ is the environment name, e.g., e.g., \Verb[commandchars=!()]+\!tcbth()listoftheorems+.  Please notice that there is a `s' (plural) after \verb+<envname>+.
  \end{description}
\end{description}

\section{Example}
\label{sec:examples}

Let's start by creating two new environments, one for \emph{algorithms} and another for \emph{examples}, both defaulting to a gray frame, the former with a yellowish background and the latter with a lighter gray background.

\begin{verbatim}
\cthnewtheorem{algorithm}{Algorithm}[coltitle=black, colback=yellow!10,
                                       colframe=black!15]
\cthnewtheorem{example}{Example}[coltitle=black, colback=black!5,
                                   colframe=black!30]  
\end{verbatim}

\cthnewtheorem{algorithm}{Algorithm}[coltitle=black, colback=yellow!10, colframe=black!15]
\cthnewtheorem{example}{Example}[coltitle=black, colback=black!5, colframe=black!30]


An algorithm box will be created with:
\begin{verbatim}
\begin{cthalgorithm}{Advance a counter to the next value in a domain
                    $\omega \in \mathbb{N}$.}

Algorithm body here!
\end{cthalgorithm}
\end{verbatim}

\newcommand{\bracesemptyset}{\ensuremath{\lbrace\,\rbrace}}

\begin{cthalgorithm}{Advance a counter to the next value in a domain $\omega \in \mathbb{N}$.}
  \label{alg:advance1}
\begin{algorithmic}[1]
  \Statex \Input $\alpha$: The current value; and $\omega$: the domain.
  \Statex \Output The next value of $\alpha$ within the domain $\omega$.
  \LComment{\color{blue}
            e.g., $\alpha = 3 \And \omega = \lbrace 8, 3, 2, 21, 5, 1 \rbrace \rightarrow 5$}

  \Vspace

  \Function{advance}{$\alpha$: int, $\omega$: set} $\rightarrow$ int \textbf{is}
    % \Statex\Comment{As we are incrementing one by one on the operation IDs, the complexity of this function is linear in the value of the largest operation id.}
    \Let {\alpha} {\alpha + 1}
                    \Comment{try the next value}
    \While{$\alpha \not\in \omega \And \omega \neq \bracesemptyset$}
                    \Comment{if this value is not in the domain}
      \Let {\alpha} {\alpha + 1}
                    \Comment{try the next value}
    \EndWhile
    \If{$\omega \neq \bracesemptyset$}
      \Let {\omega} {\omega \,\backslash \lbrace \alpha \rbrace}
                    \Comment{remove the value from the domain}
    \EndIf
    \State \Return $\alpha$
                    \Comment{\color{red} the next value (or the last value plus one if no more values)}
  \EndFunction
\end{algorithmic}
\end{cthalgorithm}

Now, let's rewrite \autoref{alg:advance1}, but now with a different customized visual, just for this entry!  The customization (3rd) argument is passed straight to the \texttt{tcolorbox} environment, so anything valid for \texttt{tcolorbox} is also valid here.

\begin{cthalgorithm}{Advance a counter to the next value in a domain $\omega \in \mathbb{N}$, but now with a customized visual. Also, notice that this algorithm breaks the page boundaries.}[coltitle=white, colback=green!10, colframe=green!70!black, fonttitle=\sffamily\bfseries\large, colbacktitle=red!50!white]
  \label{alg:advance2}
\begin{algorithmic}[1]
  \Statex \Input $\alpha$: The current value; and $\omega$: the domain.
  \Statex \Output The next value of $\alpha$ within the domain $\omega$.
  \LComment{\color{blue}
            e.g., $\alpha = 3 \And \omega = \lbrace 8, 3, 2, 21, 5, 1 \rbrace \rightarrow 5$}

  \Vspace

  \Function{advance}{$\alpha$: int, $\omega$: set} $\rightarrow$ int \textbf{is}
    % \Statex\Comment{As we are incrementing one by one on the operation IDs, the complexity of this function is linear in the value of the largest operation id.}
    \Let {\alpha} {\alpha + 1}
                    \Comment{try the next value}
    \While{$\alpha \not\in \omega \And \omega \neq \bracesemptyset$}
                    \Comment{if this value is not in the domain}
      \Let {\alpha} {\alpha + 1}
                    \Comment{try the next value}
    \EndWhile
    \If{$\omega \neq \bracesemptyset$}
      \Let {\omega} {\omega \,\backslash \lbrace \alpha \rbrace}
                    \Comment{remove the value from the domain}
    \EndIf
    \State \Return $\alpha$
                    \Comment{\color{red} the next value (or the last value plus one if no more values)}
  \EndFunction
\end{algorithmic}
\end{cthalgorithm}

Now, let's add an example here, this time using the default visual that was given when creating the environment with \verb+\cthnewtheorem+…

\begin{cthexample}{This is an example!}
  \emph{\kant[3]}
\end{cthexample}

And now an example with no caption and a different visual…  this example will not go into the \verb+\listofexamples+ below!

\begin{cthexample}{}[coltitle=yellow, colback=blue!30, colframe=blue!70]
  \emph{\kant[4]}
\end{cthexample}

Now let's print the lists of algorithms and examples. Remember to add the prefix \texttt{cthth} to the \texttt{listof}, i.e., \verb+\cthlistofalgorithms+ and \verb+\cthlistofexamples+!

\cthlistofalgorithms

\cthlistofexamples

\end{document}