\documentclass{article} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% TCBTHEOREM stuff \usepackage{coloredtheorem} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXAMPLE document \usepackage[margin=1.6in]{geometry} \usepackage{fancyvrb} \usepackage{minted} \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 {\footnotesize(v1.0.2)}} \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 that allows to write stuff inside boxes from \texttt{tcolorbox}. If necessary the boxes gracefully overflow to the next page. This package takes no options and includes \texttt{tcolorbox} if necessary. You may include \texttt{tcolorbox} with your own favourite options prior to including this package. Akin to \mintinline{TeX}+\newtheorem+ from the \texttt{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 \mintinline{TeX}+\label{…}+ and \mintinline{TeX}+\ref{…}+ work as expected. There is also a command to generate the corresponding \emph{list of …} \section{Usage} \label{sec:usage} \definecolor{mycgreen}{RGB}{57,126,27} \newcommand\ca[1]{\textcolor{blue}{#1}} \newcommand\co[1]{\textcolor{blue!50}{#1}} \newcommand\cc[1]{\textcolor{red!50!black}{#1}} \newcommand\ck[1]{\textcolor{mycgreen}{#1}} \begin{itemize} \item \mintinline{TeX}+\usepackage{coloredtheorem}+ \begin{itemize} \item Load the \texttt{coloredtheorem} package. This package will load \texttt{tcolorbox} if necessary. \end{itemize} \item \mintinline[escapeinside=||]{TeX}+\cthnewtheorem{|\ca{}|}{|\ca{}|}[|\co{}|]+ \begin{itemize} \item Create a new boxed \emph{algorithm-like} environment. \begin{itemize} \item \mintinline[escapeinside=||]{TeX}+|\ca{}|+ is the suffix for the new environment being defined, e.g., \ca{\texttt{algoritm}}. The effective environment name will be \mintinline[escapeinside=||]{TeX}+|\ca{cth}|+, e.g., \ca{\texttt{cthalgorithm}}. \item \mintinline[escapeinside=||]{TeX}+|\ca{}|+ is the (printable) name or the new environment being defined, e.g., \emph{Algorithm}. \item \mintinline[escapeinside=||]{TeX}+|\co{}|+ default options for the environment being defined (this argument is optional). These options are passed straight to the \texttt{tcolorbox} environment, so anything valid for \texttt{tcolorbox} is also valid here. \end{itemize} \end{itemize} \item \begin{minted}[escapeinside=||]{TeX} \begin{|\ca{ctb}|}[|\co{}|]{|\ca{}|}[|\co{}|] |\cc{}| \end{|\ca{ctb}|} \end{minted} \begin{itemize} \item Create a new \emph{algorithm-like} box with the given contents. \begin{itemize} \item \mintinline[escapeinside=||]{TeX}+|\co{}|+ is the alternative caption for the \mintinline[escapeinside=||]{TeX}+\cthlistof|\ck{s}|+ (see below). \item \mintinline[escapeinside=||]{TeX}+|\ca{}|+ is the suffix for environment name, e.g., \verb+algorithm+. \item \mintinline[escapeinside=||]{TeX}+|\ca{}|+ is the caption/title of the box. If the caption is left empty, this box will not be listed with the \mintinline[escapeinside=||]{TeX}+\cthlistof|\ck{s}|+ (see below). \item \mintinline[escapeinside=||]{TeX}+|\co{}|+ options to be passed to the \verb+tcolorbox+ environment, which will override the defaults given in \mintinline{TeX}+\cthnewalgorithm+ (this argument is optional). \item \mintinline[escapeinside=||]{TeX}+|\cc{}|+ the contents to by typeset inside the colored environment. \end{itemize} \end{itemize} \item \mintinline[escapeinside=||]{TeX}+\cthlistof|\ck{s}|+ \begin{itemize} \item \mintinline[escapeinside=||]{TeX}+|\ca{}|+ is the environment name suffix, e.g., \mintinline[escapeinside=||]{TeX}+\cthlistofalgorithms+. Please notice that there is a `s' (plural) after \mintinline[escapeinside=||]{TeX}+|\ca{}|+. \end{itemize} \end{itemize} \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{minted}[bgcolor=red!5,fontsize=\small,escapeinside=||]{TeX} \cthnewtheorem{|\ca{algorithm}|}{|\ca{Algorithm}|}[|\co{coltitle=}|black, |\co{colback=}|yellow!10, |\co{colframe=}|black!15] \cthnewtheorem{|\ca{example}|}{|\ca{Example}|}[|\co{coltitle=}|black, |\co{colback}|=black!5, |\co{colframe=}|black!30] \end{minted} \cthnewtheorem{algorithm}{Algorithm}[coltitle=black, colback=yellow!10, colframe=black!15] \cthnewtheorem{example}{Example}[coltitle=black, colback=black!5, colframe=black!30] The box with \autoref{alg:advance1}, which uses the default visual that was given when creating the environment with \mintinline{TeX}+\cthnewtheorem+ and gracefully overflows onto the next page, was created with: \begin{minted}[bgcolor=red!5,fontsize=\small,escapeinside=||]{TeX} \begin{|\ca{cthalgorithm}|}{|\co{Advance a counter to the next value in a domain}| $\omega \in \mathbb{N}$.} |\cc{Algorithm body here!}| \end{|\ca{cthalgorithm}|} \end{minted} \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} The box \autoref{expl:explstd}, which uses the default visual for the environment (as given to \mintinline{TeX}+\cthnewtheorem...+), was created with: \begin{minted}[bgcolor=red!5,fontsize=\small,escapeinside=||]{TeX} \begin{|\ca{cthexample}|}{|\co{This is an example!}|} |\cc{Example body here!}| \end{|\ca{cthexample}|} \end{minted} \begin{cthexample}{This is an example!} \label{expl:explstd} \emph{As is shown in the writings of Aristotle, the things in themselves (and it remains a mystery why this is the case) are a representation of time. Our concepts have lying before them the paralogisms of natural reason, but our a posteriori concepts have lying before them the practical emploument of our experience.} \end{cthexample} Now, let's create a new box for \autoref{alg:advance1}, but with a different customized visual, which will affect only this entry! Notice that the customization argument is passed straight to the \texttt{tcolorbox} environment, so anything valid for \texttt{tcolorbox} is also valid here. \autoref{alg:advance2} was created with the following code: \begin{minted}[bgcolor=red!5,fontsize=\small,escapeinside=||]{TeX} \begin{|\ca{cthalgorithm}|} {|\ca{Advance a counter to the next value in a domain}| $\omega \in \mathbb{N}$|\ca{, but now with a customized visual. Also, notice}| |\ca{that this algorithm breaks the page boundaries.}|} [|\co{coltitle}=|white, |\co{colback}=|green!10, |\co{colframe}=|green!70!black, |\co{colbacktitle}=|\sffamily\bfseries\large, |\co{fonttitle}|=red!50!white] |\cc{Algorithm body here!}| \end{|\ca{cthalgorithm}|} \end{minted} \begin{cthalgorithm}{Advance a counter to the next value in a domain $\omega \in \mathbb{N}$, but now with a customized visual. Notice that this algorithm also breaks the page boundaries.}[coltitle=white, colback=red!10, colframe=red!50!black, fonttitle=\sffamily\bfseries\large, colbacktitle=red!70!black] \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} And now an example with no caption and a different visual… this example will not go into the \mintinline{TeX}+\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 \ck{\texttt{cth}} to the \ck{\texttt{listof}}, i.e., \mintinline{TeX}+\cthlistofalgorithms+ and \mintinline{TeX}+\cthlistofexamples+! \cthlistofalgorithms \cthlistofexamples \end{document}