%% test-tcbpagefootnote-order.tex
%% ==============================
%% Typesetting test: the tcbpagefootnote package with
%% \tcbset{page footnote} for the whole document, with ncolumn loaded
%% before it or after it.
%%
%%   pdflatex test-tcbpagefootnote-order.tex   (or xelatex / lualatex /
%%   platex / uplatex), until there is no "Rerun" warning
%%   \def\NCOLtpffirst{}\input test-tcbpagefootnote-order
%%     (tcbpagefootnote is loaded before ncolumn)
%%   \def\NCOLtagging{}\input test-tcbpagefootnote-order  (tagged PDF)
%% "make test" takes tcbpagefootnote from ../tcbpagefootnote.  The test
%% needs tcbpagefootnote v1.8 or later.
%%
%% What is covered:
%%   * boxes on the page, one of them broken across columns: they have
%%     the key from \tcbset, and their footnotes are footnotes of the
%%     text;
%%   * a box in a figure*, in a figure and in a \spanblock*: a footnote
%%     text cannot get from there to the page, so tcbpagefootnote does
%%     not give the key to the box, and its footnotes are footnotes of
%%     the box.  For this, tcbpagefootnote compares \@footnotetext with
%%     the one of the document, which it takes after ncolumn has put
%%     its own there (a rule for the hook begindocument/end in
%%     ncolumn.sty).
%%
%% What to check:
%%   * NCOL-RESULT OK: every footnote text is on the page of its mark.
%%     A footnote of the text has the width of the footnotes of the
%%     page, a footnote of a box the width of the text of the box.  A
%%     footnote text that is lost has no page and no width;
%%   * no error, no warning of ncolumn or tcbpagefootnote, no overfull
%%     \vbox and no "% split" (of \tracingpages) in the log;
%%   * in the PDF, the boxes in the floats and in the block have their
%%     footnotes (a, b, ...) inside the box.
\ifdefined\NCOLtagging \DocumentMetadata{tagging=on}\fi
\ifdefined\CLS\else\def\CLS{article}\fi
\ifdefined\ptexversion\def\CLSOPT{dvipdfmx}\else\def\CLSOPT{}\fi
\ifdefined\NCOLopt\else\def\NCOLopt{columns=3}\fi
\expandafter\documentclass\expandafter[\CLSOPT]{\CLS}
\ifdefined\NCOLtpffirst
  \usepackage{tcbpagefootnote}
  \expandafter\usepackage\expandafter[\NCOLopt]{ncolumn}
\else
  \expandafter\usepackage\expandafter[\NCOLopt]{ncolumn}
  \usepackage{tcbpagefootnote}
\fi
\tcbuselibrary{breakable}
\input{test-common}
\tcbset{page footnote}
%% No stretch or shrink above the footnotes: a column that needs the
%% shrink is overfull by the depth of its last line (LaTeX kernel).
\skip\footins=1\skip\footins
%% A footnote of the text, of three lines
\newcommand\fn{\NCOLfootnote{note\par note\par note}}
%% A footnote of a box: its text has the width of the text of the box.
%% \NCOLnotewidth is given again after the box.
\newcommand\boxfn{\NCOLnotewidth[\hsize]\NCOLfootnote{note of the box}}
\begin{document}
%% The shrink of \textfloatsep, which test-common.tex takes away: the
%% column with the float at its bottom has a footnote, and the depth of
%% the last line of the text above the footnotes is added to its height
%% (LaTeX kernel).
\textfloatsep=20pt plus 2pt minus 4pt
\NCOLnotewidth
\tracingpages=1
\NCOLlines{4}
text\fn
\begin{tcolorbox}[title={title\fn}]
upper\fn
\end{tcolorbox}
\begin{figure*}[t]
\begin{tcolorbox}[title=A box in a float across the columns]
float\boxfn
\end{tcolorbox}
\caption{A float across the columns}
\end{figure*}
\NCOLnotewidth
\begin{figure}[b]
\begin{tcolorbox}[title=A box in a float]
float\boxfn
\end{tcolorbox}
\caption{A float in a column}
\end{figure}
\NCOLnotewidth
\NCOLlines{4}
\spanblock*[span=2,at=br]{\begin{tcolorbox}[title=A box in a spanning block]
block\boxfn
\end{tcolorbox}}
\NCOLnotewidth
\NCOLlines{4}
text\fn
%% From the first column to the last column of the page
\begin{tcolorbox}[breakable]
first\fn
\NCOLlines{24}
second\fn
\NCOLlines{30}
third\fn
\NCOLlines{6}
\end{tcolorbox}
\NCOLlines{4}
text\fn
%% Text for the page with the floats and the block
\NCOLlines{40}
text\fn
\NCOLlines{20}
\end{document}
