Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Merge branch '29-customizable-colored-boxes' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Benno2000 committed Apr 26, 2023
2 parents 6b544ec + 97c7f16 commit c24fdb8
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 22 deletions.
89 changes: 67 additions & 22 deletions beamerthemeuulm.sty
Original file line number Diff line number Diff line change
Expand Up @@ -611,52 +611,97 @@
% ---------------------------------------------
\tcbset{%
% by definig styles, we avoid their replication
% #1: extra arguments, #2: title, #3: color of the frame, #4: padding
uulm@basic-boxstyle/.style n args=4{
% #1: extra arguments, #2: title, #3: color of the frame, #4: padding, #5 boxname
uulm@basic-boxstyle/.style n args=5{
title={#2},
colframe=#3!30!uulm@boxmix,
coltitle=uulm@text,coltext=uulm@text,
before title={\setlength{\parskip}{0ex}\vphantom{/}},
colframe=#3!30,
coltitle=black,
before title={\setlength{\parskip}{0ex}\vphantom{/}\let\boxnumber\thetcbcounter\csname uulm@box@#5@titleprefix\endcsname},
after title={\let\boxnumber\thetcbcounter\csname uulm@box@#5@titlesuffix\endcsname},
fonttitle=\bfseries,
left=#4, right=#4, top=#4, bottom=#4, bottomtitle=-.5mm,
#1
},
% style definition for the normal boxes
% #1: extra arguments, #2: title, #3: color of the frame and background
uulm@boxstyle/.style n args=3{uulm@basic-boxstyle={#1}{#2}{#3}{1mm}, colback=#3!10!uulm@background},
% #1: extra arguments, #2: title, #3: color of the frame and background, #4: boxname
uulm@boxstyle/.style n args=4{uulm@basic-boxstyle={#1}{#2}{#3}{1mm}{#4}, colback=#3!10},
% style definition for their tight variant
% #1: extra arguments, #2: title, #3: color of the frame
uulm@tightboxstyle/.style n args=3{uulm@basic-boxstyle={#1}{#2}{#3}{0mm}, colback=uulm@background}
% #1: extra arguments, #2: title, #3: color of the frame, #4: boxname
uulm@tightboxstyle/.style n args=4{uulm@basic-boxstyle={#1}{#2}{#3}{0mm}{#4}, colback=white}
}

% #1: name, #2: color
\def\uulm@MakeNewBox#1#2{
% renew will not work if we define a box that does not already exist in beamer
% we could check this by \ifcsname #1\endcsname...\else...\fi
% however, for the moment this is not necessary
% in the definition #1 and #2 refer to the arguments of \uulm@MakeNewBox
% [optional prefix] | name | color | [optional suffix]
\newcommandx\uulm@MakeNewBox[4][1={},4={}]{%
% in the definition #2 and #3 refer to the arguments of \uulm@MakeNewBox
% while ##1 and ##2 to refer to the arguments passed on to the new tcolorbox.
% therefore, with '\uulm@MakeNewBox{definition}{orange}', we create a new tcolorbox
% named 'definition' which wenn called with '\begin{definition}[top=10mm]{My title}...'
% will result in the option list 'uulm@boxstyle={top=10mm}{My title}{orange}'
\renewtcolorbox{#1}[2][]{uulm@boxstyle={##1}{##2}{#2}}
% first we assure, that we can build this box
\newtcolorbox[auto counter,reset counter on overlays]{#2}[2][]{uulm@boxstyle={##1}{##2}{uulm@box@#2}{#2}}
% here, we re-create the old macros (e.g. '\mydefinition')
% 'capture=minipage' ensures their behavior is similar to the previous one (the default for
% tcbox would be hbox and no longer fill the width)
\expandafter\newtcbox\csname my#1\endcsname[2][]{capture=minipage,uulm@boxstyle={##1}{##2}{#2}}
\expandafter\newtcbox\csname my#2\endcsname[2][]{capture=minipage,uulm@boxstyle={##1}{##2}{uulm@box@#2}{#2}}%
% now, we do the same for the tight-version of the boxes
\newtcolorbox{#1tight}[2][]{uulm@tightboxstyle={##1}{##2}{#2}}
\expandafter\newtcbox\csname my#1tight\endcsname[2][]{capture=minipage,uulm@tightboxstyle={##1}{##2}{#2}}
\newtcolorbox[use counter from=#2]{#2tight}[2][]{uulm@tightboxstyle={##1}{##2}{uulm@box@#2}{#2}}%
\expandafter\newtcbox\csname my#2tight\endcsname[2][]{capture=minipage,uulm@tightboxstyle={##1}{##2}{uulm@box@#2}{#2}}%
% now, get the macros in effect:
\uulm@UpdateBoxSurround{#2}{#1}{#4}%
\uulm@UpdateBoxColor{#2}{#3}%
}
% like newBox but does not care if the box does already exist
% [optional prefix] | name | color | [optional suffix]
\newcommandx\uulm@DeclareBox[4][1={},4={}]{\csundef{#2}\csundef{end#2}\csundef{my#2}\csundef{#2tight}\csundef{end#2tight}\csundef{my#2tight}%
\uulm@MakeNewBox[#1]{#2}{#3}[#4]}


% name | prefix | suffix
\def\uulm@UpdateBoxSurround#1#2#3{%
\ifcsname #1\endcsname
\expandafter\def\csname uulm@box@#1@titleprefix\endcsname{#2}%
\expandafter\def\csname uulm@box@#1@titlesuffix\endcsname{#3}%
\else
\PackageError{beamerthemeuulm}{You can not set a box-prefix/-suffix for '#1' because there is no such box!}%
\fi}

\def\uulm@UpdateBoxPrefix#1#2{%
\ifcsname #1\endcsname
\expandafter\def\csname uulm@box@#1@titleprefix\endcsname{#2}%
\else
\PackageError{beamerthemeuulm}{You can not set a box-prefix for '#1' because there is no such box!}%
\fi}

\def\uulm@UpdateBoxSuffix#1#2{%
\ifcsname #1\endcsname
\expandafter\def\csname uulm@box@#1@titlesuffix\endcsname{#2}%
\else
\PackageError{beamerthemeuulm}{You can not set a box-suffix for '#1' because there is no such box!}%
\fi}


\def\uulm@UpdateBoxColor#1#2{%
\ifcsname #1\endcsname
\colorlet{uulm@box@#1}{#2}%
\else
\PackageError{beamerthemeuulm}{You can not change the color for '#1' to '#2' because there is no such box!}
\fi}

\let\MakeNewBox\uulm@MakeNewBox
\let\DeclareBox\uulm@DeclareBox
\let\UpdateBoxColor\uulm@UpdateBoxColor
\let\UpdateBoxPrefix\uulm@UpdateBoxPrefix
\let\UpdateBoxSuffix\uulm@UpdateBoxSuffix
\let\UpdateBoxSurround\uulm@UpdateBoxSurround

% now we simply define the boxes by name and color
% => \mydefinition and \mydefinitiontight
% furthermore defines the environment \begin{definition}{<title>} ... \end{definition}
\uulm@MakeNewBox{definition}{orange}
\uulm@DeclareBox{definition}{orange}
% => \myexample and \myexampletight
% furthermore defines the environment \begin{example}{<title>} ... \end{example}
\uulm@MakeNewBox{example}{blue}
\uulm@DeclareBox{example}{blue}
% => \mynote and \mynotetight
% furthermore defines the environment \begin{note}{<title>} ... \end{note}
\uulm@MakeNewBox{note}{red}
\uulm@DeclareBox{note}{red}
% ---------------------------------------------
31 changes: 31 additions & 0 deletions demo-slides/demoSlides.tex
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,37 @@ \subsection{Colored Boxes}
\end{mycolumns}
\end{frame}

{\MakeNewBox{amazing}{purple}
\begin{frame}{Create new and modify existing Boxes}
\begin{amazing}{An Amazing Box}
You can create new boxes with \texttt{\textbackslash MakeNewBox\{name\}\{color\}} (which will check if any of the new box commands is already taken) or \texttt{\textbackslash DeclareBox\{name\}\{color\}} (which may overwrite existing commands). This box was created by \texttt{\textbackslash MakeNewBox\{amazing\}\{purple\}}.
\end{amazing}
\bigskip
{\UpdateBoxColor{definition}{teal}
\begin{definition}{This is a Definition}
With \texttt{\textbackslash UpdateBoxColor\{name\}\{color\}} you can change the color of a box (locally to the current group). This definition was changed with \texttt{\textbackslash UpdateBoxColor\{definition\}\{teal\}}.
\end{definition}}
\begin{definition}{Another Definition}
This definition appears outside of the group, so \texttt{\textbackslash UpdateBoxColor\{definition\}\{teal\}} is no longer active.
\end{definition}
\end{frame}
}
{\MakeNewBox[Improved-Box: ]{improved}{purple}[\hfill Jeah! \boxnumber]
\begin{frame}{Counting Boxes!}
\UpdateBoxPrefix{definition}{Definition~\boxnumber: }%
\begin{definition}{Hey look at my number!}
With \texttt{\textbackslash UpdateBoxPrefix\{name\}\{prefix\}} you can change text to appear before the title of a box (locally to the current group). The macro \texttt{\textbackslash boxnumber} refers to the number of the current box that is robust against beamer overlays (but you do not have to use it).\medskip

This box was updated with \texttt{\textbackslash UpdateBoxPrefix\{definition\}\{Definition~\textbackslash boxnumber: \}}.
Similarly, there is \texttt{\textbackslash UpdateBoxSuffix\{name\}\{suffix\}} for text to appear after the title. As a comfort macro, there is \texttt{\textbackslash UpdateBoxSurround\{name\}\{prefix\}\{suffix\}}.
\end{definition}
\bigskip
\onslide<2->{\begin{improved}{This can be done at construction!}
Both \texttt{\textbackslash MakeNewBox[prefix]\{name\}\{color\}[postfix]} and \texttt{\textbackslash DeclareBox[prefix]\{name\}\{color\}[postfix]} have optional arguments that allow to set the prefix and suffix at construction. This box was created with \texttt{\textbackslash MakeNewBox[Improved-Box: ]\{improved\}\{purple\}[\textbackslash hfill Jeah! \textbackslash boxnumber]}.
\end{improved}}%
\end{frame}
}

\section{Slide Layouts}

\subsection{Multiple Columns}
Expand Down

0 comments on commit c24fdb8

Please sign in to comment.