% !TeX root = tcolorbox.tex
% include file of tcolorbox.tex (manual of the LaTeX package tcolorbox)
\clearpage
\section{Library 'theorems'}\label{sec:theorems}
The library is loaded by a package option or inside the preamble by:
\begin{dispListing}
\tcbuselibrary{theorems}
\end{dispListing}
This also loads the package |amsmath|.

\subsection{Macros of the Library}

\begin{docCommand}{tcbmaketheorem}{\marg{name}\marg{display name}\marg{options}\marg{counter}\marg{prefix}}
  Creates a new environment \meta{name} based on |tcolorbox| to frame a
  (mathematical) theorem. The \meta{display name} is used in the title line
  with a number, e.\,g. \mbox{\flqq Theorem 5.1\frqq}.
  The \meta{options} are given to the underlying |tcolorbox| to control
  the appearance.
  The \meta{counter} is used for automatic numbering.
  The new environment \meta{name} takes one optional and two mandatory
  parameters. The optional parameter supplements the options and should be
  used only in rare cases.
  The first mandatory parameter is the title text for the theorem and
  the second mandatory parameter is a \meta{marker}. The theorem is
  automatically labeled with \meta{prefix}|:|\meta{marker}.
\begin{dispExample}
\tcbmaketheorem{theo}{My Theorem}{colback=green!5,colframe=green!35!black,
  fonttitle=\bfseries}{texercise}{th}

\begin{theo}{This is my title}{theoexample}
  This is the text of the theorem. As can be seen, the counter \texttt{texercise}
  is reused. The theorem is numbered with \ref{th:theoexample} and is
  given on page \pageref{th:theoexample}.
\end{theo}
\end{dispExample}
\end{docCommand}


\begin{docCommand}{tcboxmath}{\oarg{options}\marg{mathematical box content}}
  Creates a \refEnv{tcolorbox} which is fitted to the width of the given
  \meta{mathematical box content}. This box is intended to be applied as
  part of a larger formula and may be used as replacement for the |\boxed|
  macro of |amsmath|.

\begin{dispExample}
\begin{equation}
\tcbset{fonttitle=\scriptsize}
\tcboxmath[colback=LightBlue!25!white,colframe=blue]{ a^2 = 16 }
\quad \Rightarrow \quad
\tcboxmath[colback=Salmon!25!white,colframe=red,title=Implication]%
  { a = 4 ~\vee~ a=-4. }
\end{equation}
\end{dispExample}
\end{docCommand}

\clearpage
\begin{docCommand}{tcbhighmath}{\oarg{options}\marg{mathematical box content}}
  This is a special case of the \refCom{tcboxmath} macro which uses
  the style \refKey{/tcb/highlight math}.
  It is intended to provide context sensitive highlighting of formula parts.
  The color settings via \refKey{/tcb/highlight math style} may be different
  inside theorems or other colored areas and outside.

\begin{dispExample}
\tcbset{myformula/.style={colback=yellow!10!white,colframe=red!50!black,
  highlight math style={colback=LightBlue!50!white,colframe=Navy}}}

\begin{align}
  \tcbhighmath{\sum\limits_{n=1}^{\infty} \frac{1}{n}} &= \infty.\\
  \int x^2 ~\text{d}x                     &= \frac13 x^3 + c.
\end{align}

\begin{tcolorbox}[ams align,myformula]
  \tcbhighmath{\sum\limits_{n=1}^{\infty} \frac{1}{n}} &= \infty.\\
  \int x^2 ~\text{d}x                     &= \frac13 x^3 + c.
\end{tcolorbox}
\end{dispExample}
\end{docCommand}


\clearpage
\subsection{Option Keys of the Library}


\begin{docTcbKey}{theorem}{=\marg{display name}\marg{counter}\marg{title}\marg{marker}}{no default}
  This key is internally used by \refCom{tcbmaketheorem}, but can be used
  directly in a |tcolorbox| for a more flexible approach.
  The \meta{display name} is used together with the increased \meta{counter} value
  and the \meta{title} for the title line of the box. Additionally, a
  |\label| with the given \meta{marker} is created.
\begin{dispExample}
\begin{tcolorbox}[colback=green!10,colframe=green!50!black,arc=4mm,
                  theorem={Test}{texercise}{Direct usage}{myMarker}]
Here, we see the test \ref{myMarker}.
\end{tcolorbox}
\end{dispExample}
For a common appearance inside the document, the key |theorem| should not be
used directly as in the example above, but as part of a new environment
created by hand or using \refCom{tcbmaketheorem}.
\end{docTcbKey}


\begin{docTcbKey}{highlight math}{}{style, no value}
  Predefined style which is used for \refCom{tcbhighmath}.
  It can be changed comfortable with \refKey{/tcb/highlight math style}.
\end{docTcbKey}


\begin{docTcbKey}{highlight math style}{=\meta{style definition}}{style, no default}
  Changes the definition for \refKey{/tcb/highlight math} to the given
  \meta{style definition}. See \refCom{tcbhighmath} for an example.
\end{docTcbKey}

\begin{docTcbKey}{math upper}{}{style, no value}
  Sets the upper part to mathematical mode with font |\displaystyle|.
\end{docTcbKey}

\begin{docTcbKey}{math lower}{}{style, no value}
  Sets the lower part to mathematical mode with font |\displaystyle|.
\end{docTcbKey}

\begin{docTcbKey}{math}{}{style, no value}
  Sets the upper part \emph{and} lower part to mathematical mode with font |\displaystyle|.
\begin{dispExample}
\begin{tcolorbox}[math,colback=yellow!10!white,colframe=red!50!black]
  \sum\limits_{n=1}^{\infty} \frac{1}{n} = \infty.
\end{tcolorbox}
\end{dispExample}
\end{docTcbKey}


\clearpage
\begin{marker}
  The following styles are only tested to work with the original |amsmath| environments.
  If e.g. the |equation| environment is redefined as |gather|, then
  \refKey{/tcb/ams equation} should / could not be used. Obviously, you are encouraged
  to use \refKey{/tcb/ams gather} in this case.
\end{marker}

\begin{docTcbKey}{ams equation upper}{}{style, no value}
  Adds an |amsmath| |equation| environment to the begin and to the end
  if the upper part.
\end{docTcbKey}

\begin{docTcbKey}{ams equation lower}{}{style, no value}
  Adds an |amsmath| |equation| environment to the begin and to the end
  if the lower part.
\end{docTcbKey}

\begin{docTcbKey}{ams equation}{}{style, no value}
  Adds an |amsmath| |equation| environment to the begin and to the end
  if the upper \emph{and} lower part.
\begin{dispExample}
\begin{tcolorbox}[ams equation,colback=yellow!10!white,colframe=red!50!black]
  \sum\limits_{n=1}^{\infty} \frac{1}{n} = \infty.
\end{tcolorbox}
\end{dispExample}
\end{docTcbKey}

\begin{docTcbKey}{ams equation* upper}{}{style, no value}
  Adds an |amsmath| |equation*| environment to the begin and to the end
  if the upper part.
\end{docTcbKey}

\begin{docTcbKey}{ams equation* lower}{}{style, no value}
  Adds an |amsmath| |equation*| environment to the begin and to the end
  if the lower part.
\end{docTcbKey}

\begin{docTcbKey}{ams equation*}{}{style, no value}
  Adds an |amsmath| |equation*| environment to the begin and to the end
  if the upper \emph{and} lower part.
\begin{dispExample}
\begin{tcolorbox}[ams equation*,colback=yellow!10!white,colframe=red!50!black]
  \sum\limits_{n=1}^{\infty} \frac{1}{n} = \infty.
\end{tcolorbox}
\end{dispExample}
\end{docTcbKey}

\clearpage
\begin{docTcbKey}{ams align upper}{}{style, no value}
  Adds an |amsmath| |align| environment to the begin and to the end
  if the upper part.
\end{docTcbKey}

\begin{docTcbKey}{ams align lower}{}{style, no value}
  Adds an |amsmath| |align| environment to the begin and to the end
  if the lower part.
\end{docTcbKey}

\begin{docTcbKey}{ams align}{}{style, no value}
  Adds an |amsmath| |align| environment to the begin and to the end
  if the upper \emph{and} lower part.
\begin{dispExample}
\begin{tcolorbox}[ams align,colback=yellow!10!white,colframe=red!50!black]
  \sum\limits_{n=1}^{\infty} \frac{1}{n} &= \infty.\\
  \int x^2 ~\text{d}x                     &= \frac13 x^3 + c.
\end{tcolorbox}
\end{dispExample}
\end{docTcbKey}

\begin{docTcbKey}{ams align* upper}{}{style, no value}
  Adds an |amsmath| |align*| environment to the begin and to the end
  if the upper part.
\end{docTcbKey}

\begin{docTcbKey}{ams align* lower}{}{style, no value}
  Adds an |amsmath| |align*| environment to the begin and to the end
  if the lower part.
\end{docTcbKey}

\begin{docTcbKey}{ams align*}{}{style, no value}
  Adds an |amsmath| |align*| environment to the begin and to the end
  if the upper \emph{and} lower part.
\begin{dispExample}
\begin{tcolorbox}[ams align*,colback=yellow!10!white,colframe=red!50!black]
  \sum\limits_{n=1}^{\infty} \frac{1}{n} &= \infty.\\
  \int x^2 ~\text{d}x                     &= \frac13 x^3 + c.
\end{tcolorbox}
\end{dispExample}
\end{docTcbKey}

\clearpage
\begin{docTcbKey}{ams gather upper}{}{style, no value}
  Adds an |amsmath| |gather| environment to the begin and to the end
  if the upper part.
\end{docTcbKey}

\begin{docTcbKey}{ams gather lower}{}{style, no value}
  Adds an |amsmath| |gather| environment to the begin and to the end
  if the lower part.
\end{docTcbKey}

\begin{docTcbKey}{ams gather}{}{style, no value}
  Adds an |amsmath| |gather| environment to the begin and to the end
  if the upper \emph{and} lower part.
\begin{dispExample}
\begin{tcolorbox}[ams gather,colback=yellow!10!white,colframe=red!50!black]
  \sum\limits_{n=1}^{\infty} \frac{1}{n} = \infty.\\
  \int x^2 ~\text{d}x = \frac13 x^3 + c.
\end{tcolorbox}
\end{dispExample}
\end{docTcbKey}

\begin{docTcbKey}{ams gather* upper}{}{style, no value}
  Adds an |amsmath| |gather*| environment to the begin and to the end
  if the upper part.
\end{docTcbKey}

\begin{docTcbKey}{ams gather* lower}{}{style, no value}
  Adds an |amsmath| |gather*| environment to the begin and to the end
  if the lower part.
\end{docTcbKey}

\begin{docTcbKey}{ams gather*}{}{style, no value}
  Adds an |amsmath| |gather*| environment to the begin and to the end
  if the upper \emph{and} lower part.
\begin{dispExample}
\begin{tcolorbox}[ams gather*,colback=yellow!10!white,colframe=red!50!black]
  \sum\limits_{n=1}^{\infty} \frac{1}{n} = \infty.\\
  \int x^2 ~\text{d}x = \frac13 x^3 + c.
\end{tcolorbox}
\end{dispExample}
\end{docTcbKey}


\clearpage
\begin{docTcbKey}{ams nodisplayskip upper}{}{style, no value}
  Neutralizes the |\abovedisplayskip| of a following |align| or |gather|
  environment for the upper part. Note that the text content has to
  start with such a formula.
\end{docTcbKey}


\begin{docTcbKey}{ams nodisplayskip lower}{}{style, no value}
  Neutralizes the |\abovedisplayskip| of a following |align| or |gather|
  environment for the lower part. Note that the text content has to
  start with such a formula.
\end{docTcbKey}


\begin{docTcbKey}{ams nodisplayskip}{}{style, no value}
  Neutralizes the |\abovedisplayskip| of a following |align| or |gather|
  environment for the upper part \emph{and} lower part.
  Note that the text content has to start with such a formula.
\begin{dispExample}
\begin{tcolorbox}[ams nodisplayskip,colback=yellow!10!white,colframe=red!50!black]
  \begin{gather}
  \sum\limits_{n=1}^{\infty} \frac{1}{n} = \infty.\\
  \int x^2 ~\text{d}x = \frac13 x^3 + c.
  \end{gather}
  And now for something completely different.
\end{tcolorbox}
\end{dispExample}
\end{docTcbKey}

\bigskip
New colored mathematical environments are easily created using
\refCom{newtcolorbox}:

\begin{dispExample}
\newtcolorbox{mymath}{ams gather*,colback=yellow!10!white,colframe=red!50!black}

\begin{mymath}
  \sum\limits_{n=1}^{\infty} \frac{1}{n} = \infty.\\
  \int x^2 ~\text{d}x = \frac13 x^3 + c.
\end{mymath}
\end{dispExample}

\bigskip
\begin{marker}
  All described options like \refKey{/tcb/ams gather upper}, \refKey{/tcb/ams gather lower},
  \refKey{/tcb/ams gather} are (partially) setting (overwritting) the
  keys \refKey{/tcb/before upper}, \refKey{/tcb/after upper},
  \refKey{/tcb/before lower}, \refKey{/tcb/after lower}.\par
  Therefore, e.\,g.\ |\tcbset{ams gather,before upper={\text{Pythagoras:}}}|
  produces an invalid result. For this case, you are invited to use\\
  |\tcbset{ams gather,before upper app={\text{Pythagoras:}}}|,\\
  see \refKey{/tcb/before upper app}.
\end{marker}

%
\clearpage
\subsection{Examples for Definitions and Theorems}
In the following, the application of \refCom{tcbmaketheorem}
to highlight mathematical definitions, theorems, or the like is demonstrated.

At first, additional |tcb| keys are created for the appearance of
the colored boxes. It is assumed that theorems and corollaries should be
identically colored.
All following environments are numbered with a common counter, but this
can be changed easily. Here, the counter output is supplemented by
the section number.

\begin{dispListing}
%\newcounter{mytheorem}[section]  % preamble
\def\themytheorem{\thesection.\arabic{mytheorem}}

\tcbset{
  defstyle/.style={fonttitle=\bfseries\upshape, fontupper=\slshape,
              arc=0mm, colback=blue!5!white,colframe=blue!75!black},
  theostyle/.style={fonttitle=\bfseries\upshape, fontupper=\slshape,
               colback=red!10!white,colframe=red!75!black},
}
\end{dispListing}
\tcbusetemp

By \refCom{tcbmaketheorem}, commonly numbered theorem environments are
created now. |defstyle| and |theostyle| are used for the appearance.

\begin{dispListing}
\tcbmaketheorem{Definition}{Definition}{defstyle}{mytheorem}{def}
\tcbmaketheorem{Theorem}{Theorem}{theostyle}{mytheorem}{theo}
\tcbmaketheorem{Corollary}{Corollary}{theostyle}{mytheorem}{cor}
\end{dispListing}
\tcbusetemp

Now, everything is prepared for the following examples.

\begin{dispExample}
The following theorem is numbered as Theorem \ref{theo:diffbarstetig} and
referenced with the marker \texttt{theo:diffbarstetig}.\bigskip

\begin{Theorem}{Differenzierbarkeit bedingt Stetigkeit, wobei diese Benennung
  zu Testzwecken ungew\"{o}hnlich lang ist}{diffbarstetig}%
  Eine Funktion $f:I\to\mathbb{R}$ ist in $x_0\in I$ stetig, wenn $f$ in
  $x_0$ differenzierbar ist.
\end{Theorem}
\end{dispExample}


\begin{dispExample}
The following definition is numbered as Definition \ref{def:diffbarkeit} and
referenced with the marker \texttt{def:diffbarkeit}.\bigskip

\begin{Definition}{Differenzierbarkeit}{diffbarkeit}
  Eine Funktion $f:~I\to\mathbb{R}$ auf einem Intervall $I$ hei\ss{}t in
  $x_0\in I$ differenzierbar oder linear approximierbar,
  wenn der Grenzwert
  \begin{equation*}
  \lim\limits_{x\to x_0}\frac{f(x)-f(x_0)}{x-x_0}=
  \lim\limits_{h\to 0}\frac{f(x_0+h)-f(x_0)}{h}
  \end{equation*}
  existiert. Bei Existenz hei\ss{}t dieser Grenzwert Ableitung
  oder Differentialquotient von $f$ in $x_0$ und man
  schreibt f\"{u}r ihn
  \begin{equation*}
  f'(x_0)\quad\text{oder}\quad\frac{df}{dx}(x_0).
  \end{equation*}
\end{Definition}
\end{dispExample}


\begin{dispExample}
The following corollary is numbered as Corollary \ref{cor:nullstellen} and
referenced with the marker \texttt{cor:nullstellen}.\bigskip

\begin{Corollary}{Nullstellenexistenz}{nullstellen}
  Ist $f:[a,b]\to\mathbb{R}$ stetig und haben $f(a)$ und $f(b)$ entgegengesetzte
  Vorzeichen, also $f(a)f(b)<0$, so besitzt $f$ eine Nullstelle $x_0\in]a,b[$,
  also $f(x_0)=0$.
\end{Corollary}
\end{dispExample}


\begin{dispExample}
\begin{Theorem}[boxrule=2mm,toptitle=-1.5mm,bottomtitle=-1.5mm]{%
    Hinreichende Bedingung f\"{u}r Wendepunkte}{wendehinreichend}%
  $f$ sei eine auf einem Intervall $]a,b[$ dreimal stetig differenzierbare Funktion.
  Ist $f''(x_0)=0$ in $x_0\in]a,b[$ und $f'''(x_0)\ne 0$, so ist
  $(x_0,f(x_0))$ ein Wendepunkt von $f$.
\end{Theorem}
\end{dispExample}


\begin{dispExample}
% \tcbuselibrary{skins}
\tcbmaketheorem{YetAnotherTheorem}{Theorem}{enhanced,frame hidden,
  boxrule=2mm,titlerule=0mm,toptitle=1mm,bottomtitle=1mm,
  fonttitle=\bfseries\large,fontupper=\normalsize,
  coltitle=green!35!black,colbacktitle=green!15!white,
  colback=green!50!yellow!15!white,
  borderline={1pt}{0pt}{green!25!blue},
  }{mytheorem}{theo}

\begin{YetAnotherTheorem}{Mittelwertsatz f\"{u}r $n$ Variable}{mittelwertsatz_n}%
  Es sei $n\in\mathbb{N}$, $D\subseteq\mathbb{R}^n$ eine offene Menge und
  $f\in C^{1}(D,\mathbb{R})$. Dann gibt es auf jeder Strecke
  $[x_0,x]\subset D$ einen Punkt $\xi\in[x_0,x]$, so dass gilt
  \begin{equation*}
  f(x)-f(x_0) = \operatorname{grad} f(\xi)^{\top}(x-x_0)
  \end{equation*}
\end{YetAnotherTheorem}
\end{dispExample}


\clearpage
You need more attention for your theorems? Here, you are \ldots

\begin{dispExample}
% tcbuselibrary{skins}  % preamble
\begin{Theorem}[enhanced,
    fuzzy halo=3mm with yellow,
    fuzzy halo=2mm with red,
    fuzzy halo=1mm with yellow,
    watermark color=red!35!white,
    watermark text={Overacting\\Fundamental Theorem}]%
  {Fundamental Theorem of Theorems}{fundamental}%
  \lipsum[1-2]
\end{Theorem}
\end{dispExample}



