%% test-key.tex
%% ============
%% Typesetting test for the values of the key "page footnote", with
%% \tcbset{page footnote} for the whole document.
%%
%%   pdflatex test-key.tex   (or xelatex / lualatex)
%%   platex  test-key.tex && dvipdfmx test-key
%%   uplatex -jobname=test-key "\def\CLS{ujarticle}\input test-key"
%%
%% What is covered:
%%   * a box that has the key only from \tcbset, unbreakable and broken
%%     across pages by \tcbbreak: each footnote text is on the page of
%%     its mark;
%%   * "page footnote=false" for a box: its footnotes are footnotes of
%%     the box, in the title, the upper and the lower part;
%%   * a box with "float" and "page footnote=false";
%%   * "page footnote=true", the key given again after "false", and
%%     the key given again after "after skip" (also for a broken box);
%%   * \tcbset{page footnote=false} in a group;
%%   * keys that set a hook as a whole (before title, before upper,
%%     before lower, after, after skip) after the key: the box keeps
%%     the key, also a broken box; with "page footnote=false" before
%%     them, it does not get it;
%%   * boxes from which a footnote text cannot get to the page have
%%     footnotes of the box: a box with "float" or "float*" (with and
%%     without the key in its options), a box in a figure, in a
%%     minipage, in a \parbox, and a box with the key in a box without
%%     the key (also three levels deep);
%%   * \tcbox, \tcbox[on line] and a box of \newtcbox in a paragraph;
%%   * "reset" after the key, the key in a style, and the key for every
%%     box (every box/.append style, \tcbsetforeverylayer): a box
%%     inside a box has page footnotes then;
%%   * hooks with a macro parameter (##1) before and after the key,
%%     the "app" and "pre" keys of the hooks library after the key,
%%     "parbox=false", and "force nobeforeafter" before the key.
%%
%% What to check:
%%   * TPF-RESULT OK, TPF-COUNTER OK, and no error or warning.
\ifdefined\CLS\else\def\CLS{article}\fi
\ifdefined\ptexversion\def\CLSOPT{dvipdfmx}\else\def\CLSOPT{}\fi
\expandafter\documentclass\expandafter[\CLSOPT]{\CLS}
\usepackage{tcbpagefootnote}
\tcbuselibrary{breakable,xparse}
\ifdefined\TPFhyperref\usepackage{hyperref}\fi
\input{test-common}
\tcbset{page footnote}
\newtcolorbox{floatbox}[1][]{float, page footnote=false, #1}
\NewTColorBox{floatnote}{ O{} }{float, page footnote = false, #1}
\newtcbox{\TPFonline}{on line, size=small}
\tcbset{TPFnote/.style={page footnote, before upper=\itshape}}
\begin{document}
\section*{The key from tcbset}

\begin{tcolorbox}[title={A box\TPFfootnote{A footnote of the title.}}]
The key is given by tcbset\TPFfootnote{A footnote of the upper part.}.
\tcblower
The lower part\TPFfootnote{A footnote of the lower part.}.
\end{tcolorbox}

\begin{tcolorbox}[page footnote=false,
  title={Without the key\TPFfootnote[box]{A footnote of the title.}}]
A box with false\TPFfootnote[box]{A footnote of the box.}.
\tcblower
The lower part\TPFfootnote[box]{A footnote of the box.}.
\end{tcolorbox}

\begin{floatbox}
A float box with false\TPFfootnote[box]{A footnote of the float box.}.
\end{floatbox}

\begin{tcolorbox}[page footnote=true]
A box with true\TPFfootnote{A footnote with true.}.
\end{tcolorbox}

\begin{tcolorbox}[page footnote=false, page footnote]
The key after false\TPFfootnote{A footnote with the key after false.}.
\end{tcolorbox}

\begin{tcolorbox}[after skip=3pt, page footnote]
The key again after another key\TPFfootnote{A footnote with the key
  given twice.}.
\end{tcolorbox}

\begingroup
\tcbset{page footnote=false}
\begin{tcolorbox}
False by tcbset\TPFfootnote[box]{A footnote of the box.}.
\end{tcolorbox}
\begin{tcolorbox}[page footnote]
The key after false by tcbset\TPFfootnote{A footnote with the key.}.
\end{tcolorbox}
\endgroup

\begin{tcolorbox}
The key is given by tcbset again\TPFfootnote{A footnote after the
  group.}.
\end{tcolorbox}

\section*{Keys that set a hook after the key}

\begin{tcolorbox}[before title=\scshape, before upper=\itshape,
  before lower=\bfseries, after skip=3pt,
  title={Hooks\TPFfootnote{A footnote of the title.}}]
The hooks are set after tcbset\TPFfootnote{A footnote of the upper part.}.
\tcblower
The lower part\TPFfootnote{A footnote of the lower part.}.
\end{tcolorbox}

\begin{tcolorbox}[page footnote, after=\par, before upper*=\itshape]
The hooks are set after the key\TPFfootnote{A footnote with the key
  before the hooks.}.
\end{tcolorbox}

\begin{tcolorbox}[page footnote=false, before upper=\itshape,
  after skip=3pt]
The hooks are set after false\TPFfootnote[box]{A footnote of the box.}.
\end{tcolorbox}

\section*{Broken boxes}

\begin{tcolorbox}[breakable,
  title={A broken box\TPFfootnote{A footnote of the title.}}]
The first part of a broken box\TPFfootnote{A footnote of the first part.}.
\tcbbreak
The second part of the box\TPFfootnote{A footnote of the second part.}.
\tcblower
The lower part of the box\TPFfootnote{A footnote of the lower part.}.
\end{tcolorbox}

\begin{tcolorbox}[breakable, after skip=3pt, page footnote]
The first part, the key given twice\TPFfootnote{A footnote of the
  first part.}.
\tcbbreak
The second part\TPFfootnote{A footnote of the second part.}.
\end{tcolorbox}

\begin{tcolorbox}[breakable, before upper=\itshape, after skip=3pt]
The first part, the hooks set after tcbset\TPFfootnote{A footnote of
  the first part.}.
\tcbbreak
The second part\TPFfootnote{A footnote of the second part.}.
\end{tcolorbox}

\begin{tcolorbox}[breakable, page footnote=false]
The first part of a broken box with false.
\tcbbreak
The second part\TPFfootnote[box]{A footnote of the box, which is
  where the box ends.}.
\end{tcolorbox}

\TPFcounter{footnote}{20}

\section*{Boxes from which a footnote text cannot get to the page}

\begin{tcolorbox}[float]
A float box\TPFfootnote[box]{A footnote of the float box.}.
\end{tcolorbox}

\begin{tcolorbox}[float, page footnote]
A float box with the key\TPFfootnote[box]{A footnote of the float box.}.
\end{tcolorbox}

\begin{tcolorbox}[page footnote, float*]
A box with float*\TPFfootnote[box]{A footnote of the float box.}.
\end{tcolorbox}

\begin{floatnote}
A float box with false\TPFfootnote[box]{A footnote of the float box.}.
\end{floatnote}

\begin{tcolorbox}[page footnote=false, float]
False before float\TPFfootnote[box]{A footnote of the float box.}.
\end{tcolorbox}

\begin{figure}[ht]
\begin{tcolorbox}
A box in a figure\TPFfootnote[box]{A footnote of the box in the figure.}.
\end{tcolorbox}
\caption{A figure}
\end{figure}

\noindent
\begin{minipage}{.8\linewidth}
\begin{tcolorbox}
A box in a minipage\TPFfootnote[box]{A footnote of the box in the
  minipage.}.
\end{tcolorbox}
The text of the minipage\TPFfootnote[box]{A footnote of the minipage.}.
\end{minipage}

\noindent
\parbox{.8\linewidth}{%
  \begin{tcolorbox}[page footnote]
  A box in a parbox\TPFfootnote[box]{A footnote of the box in the
    parbox.}.
  \end{tcolorbox}}

\begin{tcolorbox}[page footnote=false]
A box without the key\TPFfootnote[box]{A footnote of the outer box.}.
\begin{tcolorbox}[page footnote]
A box with the key inside\TPFfootnote[box]{A footnote of the inner box.}.
\end{tcolorbox}
\end{tcolorbox}

\begin{tcolorbox}
A box with the key\TPFfootnote{A footnote of the outer box.}.
\begin{tcolorbox}[page footnote]
With the key inside\TPFfootnote{A footnote of the inner box.}.
\end{tcolorbox}
\begin{tcolorbox}
Without the key inside\TPFfootnote[box]{A footnote of the inner box.}.
\begin{tcolorbox}[page footnote]
With the key on the third level\TPFfootnote[box]{A footnote of the
  box on the third level.}.
\end{tcolorbox}
\end{tcolorbox}
\end{tcolorbox}

Text\TPFfootnote{A footnote of the body text.}.
\TPFcounter{footnote}{23}
\clearpage

\section*{Other ways to give the key}

A paragraph with \tcbox{a tcbox\TPFfootnote{A footnote of the tcbox.}}
and \tcbox[on line]{on line\TPFfootnote{A footnote of the tcbox on the
  line.}} and \TPFonline{newtcbox\TPFfootnote{A footnote of the box of
  newtcbox.}} in it.

\begin{tcolorbox}[page footnote, reset]
The key before reset\TPFfootnote[box]{A footnote of the box.}.
\end{tcolorbox}

\begin{tcolorbox}[page footnote=false, TPFnote]
A style with the key\TPFfootnote{A footnote with the style.}.
\end{tcolorbox}

\begin{tcolorbox}[TPFnote, page footnote=false]
False after the style\TPFfootnote[box]{A footnote of the box.}.
\end{tcolorbox}

\begingroup
\tcbset{every box/.append style={page footnote}}
\begin{tcolorbox}
Every box\TPFfootnote{A footnote of the outer box.}.
\begin{tcolorbox}
An inner box\TPFfootnote{A footnote of the inner box.}.
\end{tcolorbox}
\begin{tcolorbox}[page footnote=false]
An inner box with false\TPFfootnote[box]{A footnote of the box.}.
\end{tcolorbox}
\end{tcolorbox}
\endgroup

\begin{tcolorbox}
After the group\TPFfootnote{A footnote of the outer box.}.
\begin{tcolorbox}
An inner box\TPFfootnote[box]{A footnote of the box.}.
\end{tcolorbox}
\end{tcolorbox}

\section*{More keys with the key}

\begin{tcolorbox}[page footnote,
  before upper={\def\TPFtmp##1{(##1)}\TPFtmp{a}},
  after={\def\TPFtmp##1{[##1]}\par\noindent\TPFtmp{c}\par}]
Hooks with a parameter after the key\TPFfootnote{A footnote of the
  box.} \TPFtmp{b}.
\end{tcolorbox}

\begin{tcolorbox}[before upper={\def\TPFtmp##1{(##1)}\TPFtmp{a}},
  after={\def\TPFtmp##1{[##1]}\par\noindent\TPFtmp{c}\par},
  page footnote=false]
Hooks with a parameter before false\TPFfootnote[box]{A footnote of
  the box.} \TPFtmp{b}.
\end{tcolorbox}

\begin{tcolorbox}[page footnote, before upper app=\itshape,
  before upper pre=\bfseries, after app={\par\noindent After app.\par},
  after pre={\par\noindent After pre.\par}]
The app and pre keys after the key\TPFfootnote{A footnote of the box.}.
\end{tcolorbox}

\begin{tcolorbox}[page footnote, parbox=false]
With parbox=false\TPFfootnote{A footnote of the box.}.
\end{tcolorbox}

\begin{tcolorbox}[force nobeforeafter, page footnote]
With force nobeforeafter before the key\TPFfootnote{A footnote of the
  box.}.
\end{tcolorbox}

\TPFcounter{footnote}{34}
\end{document}
