%% tcbpagefootnote.tex -- documentation for the tcbpagefootnote package
%%
%% Copyright (c) 2026 Munehiro Yamamoto <munepixyz@gmail.com>
%% License: LPPL 1.3c or later
%%
%% Build: pdflatex tcbpagefootnote.tex (twice)
\documentclass{article}
\usepackage[margin=28mm]{geometry}
\usepackage{xcolor}
\usepackage{tcbpagefootnote}
\usepackage[colorlinks, allcolors=blue!50!black]{hyperref}
\newcommand*\tpfversion{v1.8 (2026/12/04)}
\newcommand*\cs[1]{\texttt{\char`\\#1}}
\newcommand*\pkg[1]{\textsf{#1}}
\newcommand*\key[1]{\texttt{#1}}
\newcommand*\meta[1]{$\langle$\textit{#1}$\rangle$}
\tcbset{colframe=black!60, colback=black!3, fonttitle=\bfseries}
\emergencystretch=2em

\title{The \pkg{tcbpagefootnote} package\\
  \large Page footnotes from inside tcolorbox}
\author{Munehiro Yamamoto\\
  \url{https://github.com/munepi/tcbpagefootnote}}
\date{\tpfversion}

\begin{document}
\maketitle

\section{Introduction}

\pkg{tcolorbox} typesets the content of a box like a \texttt{minipage}:
a \cs{footnote} inside the box is numbered with the \texttt{mpfootnote}
counter (as a, b, c) and its text is put at the bottom of the box.
This is often what you want for a box that stands apart from the text,
but not for a box that is part of the running text, such as a note or
a definition in a book: there, the footnotes should share the numbering
of the body text and go to the bottom of the page.

The \pkg{tcbpagefootnote} package adds the \pkg{tcolorbox} key
\key{page footnote} for this.  The two boxes below differ only in this
key.

\begin{tcolorbox}[title=An ordinary box]
A footnote in an ordinary box\footnote{This footnote is put at the
  bottom of the box.} is a footnote of the box.
\end{tcolorbox}

\begin{tcolorbox}[title=A box with \key{page footnote}, page footnote]
A footnote in a box with \key{page footnote}\footnote{This footnote is
  put at the bottom of the page.} is a footnote of the page, numbered
along with the footnotes of the body text.
\end{tcolorbox}

\paragraph{Supported formats/engines}
pdf\LaTeX, Xe\LaTeX, Lua\LaTeX{} (with or without Lua\TeX-ja),
p\LaTeX{} and up\LaTeX{} (with dvipdfmx); horizontal (yoko) and
vertical (tate) writing.  The package requires \pkg{tcolorbox} and
loads its \texttt{hooks} library.  With Lua\LaTeX, it also loads
\texttt{tcbpagefootnote.lua}.

\section{Usage}

\begin{verbatim}
\usepackage{tcbpagefootnote}

\begin{tcolorbox}[title=Note, page footnote]
  Text\footnote{A page footnote.}.
\end{tcolorbox}

\newtcolorbox{note}[1][]{colback=blue!5, page footnote, #1}
\tcbset{page footnote}  % for every box
\end{verbatim}

\noindent
\key{page footnote} is the same as \key{page footnote=true}.
\key{page footnote=false} takes the key back: the footnotes of the box
are footnotes of the box, as without the package.  It is given to a
box, or with \cs{tcbset} for the boxes that follow.
\begin{verbatim}
\tcbset{page footnote}
\begin{tcolorbox}[page footnote=false]
  Text\footnote{A footnote of the box.}.
\end{tcolorbox}
\end{verbatim}

\noindent
From some boxes a footnote text cannot get to the page: a box with
\key{float}, and a box in a float (\texttt{figure}, \texttt{table}),
in a \texttt{minipage}, in a \cs{parbox}, or in a \texttt{tcolorbox}
without the key.  Such a box has its footnotes as with
\key{page footnote=false}, so \verb|\tcbset{page footnote}| can be
given for a whole document.

\noindent
The key acts on the footnotes in the title, the upper part and the lower
part of the box:
\begin{itemize}
\item the marks are made with the \texttt{footnote} counter and
  \cs{thefootnote}, as in the body text;
\item the texts are collected while the box is typeset and are put into
  the ordinary footnote insertion right after the box, so that they go
  to the bottom of the page where the box is.  If the box does not fit
  on the current page and moves to the next one, its footnotes move
  with it.
\end{itemize}
\cs{footnote}\texttt{[\meta{number}]}, \cs{footnotemark} with
\cs{footnotetext}, \cs{tcbox}, and boxes with \key{page footnote} inside
each other work as usual.  An ordinary box inside a box with
\key{page footnote} keeps its own footnotes.  With \pkg{hyperref}, each
footnote mark links to its own footnote text.

\paragraph{Breakable boxes}
A \key{breakable} box that is broken across pages puts each footnote
text on the page of its mark, like the body text does, and each part of
the box leaves room for its footnotes.  This is done in one run, in a
way that depends on the engine.
\begin{itemize}
\item With Lua\LaTeX, the footnote texts are real insertions at their
  marks.  When \pkg{tcolorbox} splits the content of the box, each part
  keeps the insertions of its marks, and \pkg{tcbpagefootnote} moves
  them out of the part to its page.  The content is split as if each
  line with a footnote mark were as much higher as its footnote text
  needs at the bottom of the page.
\item With the other engines, each footnote text is typeset at its mark
  and kept in a box, and a \TeX{} mark (\cs{marks}) at the footnote
  mark tells which part the footnote belongs to.  The content is split
  again, from a copy, until the part and its footnotes fit.
\end{itemize}
With every engine, what a part leaves for its footnotes is computed
with the \cs{count}\cs{footins} and \cs{skip}\cs{footins} of the column
of the part: a package may change them from column to column (e.g.\
\pkg{ftnright} in the two columns of \LaTeX).
See also Section~\ref{sec:limitations}.

\paragraph{Breakable boxes inside breakable boxes}
\pkg{tcolorbox} does not break a box inside another box.  With the
\pkg{tcbnestbreak} package it does: a \key{breakable} box inside a
\key{breakable} box is broken together with the outer box.  If both
boxes have \key{page footnote}, the footnotes of the inner box are put
on the pages of their marks as well.

\paragraph{Tagged PDF}
With \verb|\DocumentMetadata{tagging=on}|, for example, \LaTeX{} loads
its new footnote code.  With this code, the footnote text is typeset
where its mark is, as in a \texttt{minipage}, and the typeset text is
put into the footnote insertion after the box.  In the structure tree,
the footnote (\texttt{FENote}) then directly follows its mark
(\texttt{Lbl}), as for a footnote in the body text.  The text is
typeset by the \cs{@footnotetext} of the page, in the \cs{columnwidth}
outside the box and in the normal color, not in the text color of the
box.  If a package has put code around \cs{@footnotetext}, e.g.\ to set
the footnotes in another width, it acts on the footnotes of a box as
well.

\paragraph{Footnotes that are not split}
The package works with the \pkg{footnotenosplit} package, which keeps
\TeX{} from splitting a footnote: a footnote of a box that \TeX{} moves
to the next page as a whole gets the space of \cs{footnotetopkern}
above it, as a footnote of the body text does.  In general, where the
package typesets a footnote text in a box and puts it into the
footnote insertion later, the insertion gets the parameters that the
\cs{@footnotetext} of the page has set (\cs{interlinepenalty},
\cs{splittopskip}, \cs{splitmaxdepth}, \cs{floatingpenalty}).

\paragraph{Vertical writing}
\key{page footnote} also works in tate, with the tate classes of
p\LaTeX{} and up\LaTeX{} (e.g.\ \texttt{tarticle} and
\texttt{utarticle}) and of Lua\TeX-ja (e.g.\ \texttt{ltjtarticle}).  With p\LaTeX{}
and up\LaTeX, load the \pkg{pxpgftate} package as well: without it,
TikZ/PGF, and so \pkg{tcolorbox}, draws the boxes sideways in tate.
\pkg{tcbpagefootnote} does not load it itself.
\begin{verbatim}
\documentclass[dvipdfmx]{tarticle}
\usepackage{tcbpagefootnote}
\usepackage{pxpgftate}
\end{verbatim}

\section{Errors and warnings}

\begin{description}
\item[\texttt{The key 'page footnote' takes 'true' or 'false'.}]
  The key has another value.
\item[\texttt{The 'after' code of this box no longer flushes the page
  footnotes.}] The footnotes are put by the \key{after pre} code of the
  \texttt{hooks} library.  \key{force nobeforeafter}, which sets the
  \texttt{after} code when all the options of the box are set, removes
  it when it comes after \key{page footnote}: give it before the key.
  The other keys that set a hook of the box as a whole
  (\key{before title}, \key{before upper}, \key{before lower},
  \key{after}, \key{after skip}, \key{nobeforeafter}) can come before
  or after \key{page footnote}: the hooks get the code of the key
  again when all the options of the box are set.
\item[\texttt{The tcolorbox key 'page footnote' is already defined.}]
  Another package defines a key of the same name; \pkg{tcbpagefootnote}
  does not redefine it.
\item[\texttt{This box is broken across pages.} (warning)] Only in
  \texttt{multicols}; see below.
\end{description}

\section{Limitations}
\label{sec:limitations}

\begin{itemize}
\item \key{page footnote} does nothing for a box from which a footnote
  text cannot get to the page: a box with \key{float}, and a box that
  is typeset inside another box (in a float, in a \texttt{minipage},
  in a \cs{parbox}, in a cell of a \texttt{tabular}) or in a
  \texttt{tcolorbox} without the key.  Its footnotes are footnotes of
  the box.  A box in a cell of a \texttt{longtable} or a
  \texttt{tabularx} keeps the key, since these environments take the
  footnote texts to the page themselves.  A \cs{tcbox} has no
  footnotes of the box, so in such a place its footnote texts are
  lost, as with \pkg{tcolorbox} alone.
\item In a \texttt{multicols} environment, where the footnotes are
  below all the columns, a \key{breakable} box that is broken puts the
  footnote texts of all its parts where the box ends.  The package
  issues a warning for such a box when it has footnotes.
\item With an engine other than Lua\TeX, a footnote inside a box of the
  content of a broken box (e.g.\ a \cs{footnotetext} in a
  \texttt{tabular}) can be put on the page after that of its mark:
  \TeX{} does not see the mark of such a footnote when the content is
  split.  Also, the footnote text is typeset through
  \cs{@footnotetext} with \cs{insert} redefined; a class or package
  whose \cs{@footnotetext} does not use \cs{insert}\cs{footins} is not
  supported there.
\item With Lua\LaTeX, the part of a broken box on a page that has no
  footnote before the box is up to \cs{skip}\cs{footins} (the
  space above the footnotes) shorter than without \key{page footnote},
  when the part has no footnote but the rest of the box has one.
\item With p\LaTeX{} and up\LaTeX{} in tate, a \cs{footnotetext} in
  vertical mode (e.g.\ right after a box) does not work with the new
  footnote code of \LaTeX{} (\cs{DocumentMetadata}), with or without
  this package.  Put it in a paragraph.
\end{itemize}

\section{Tests}

\verb|make test| compiles the test files with pdf\LaTeX, Xe\LaTeX,
Lua\LaTeX, p\LaTeX{} and up\LaTeX{} (+ dvipdfmx) and checks the log.
The tests pass with \TeX{} Live 2025 (frozen: \LaTeX{} 2025-11-01,
\pkg{tcolorbox} 6.9.0) and with \TeX{} Live 2026; the tests with
tagging are run with \TeX{} Live 2026 only.
For every footnote, \texttt{test-common.tex} records in the
\texttt{.aux} file at shipout the page and the mark of both the footnote
mark and the footnote text, and whether the text is set in the full
\cs{columnwidth} of the page (a page footnote) or in a box; when the
\texttt{.aux} file is read back at \verb|\end{document}|, it checks
that every text is typeset exactly once, with its own mark, on the
expected page (\texttt{TPF-RESULT OK}).

\begin{center}
\begin{tabular}{ll}
  \hline
  Test & What it covers\\
  \hline
  \texttt{test-basic.tex}     & title/upper/lower, nesting, \cs{tcbox},
                                a box moved to the next page\\
  \texttt{test-hyperref.tex}  & \texttt{test-basic.tex} with
                                \pkg{hyperref}: no duplicate anchors\\
  \texttt{test-breakable.tex} & a box broken by \cs{tcbbreak}, an
                                unbroken breakable box\\
  \texttt{test-key.tex}       & the values of the key, with
                                \verb|\tcbset{page footnote}|; boxes\\
                              & from which a footnote text cannot get
                                to the page\\
  \texttt{test-key-libs.tex}  & boxes of the libraries (raster,
                                theorems, skins, listings)\\
                              & with \verb|\tcbset{page footnote}|\\
  \texttt{test-breakable-long.tex} & boxes that \TeX{} breaks across
                                several pages\\
  \texttt{test-twocolumn.tex} & boxes broken across the two columns of
                                \LaTeX, also with \pkg{ftnright}\\
  \texttt{test-nested.tex}    & with \pkg{tcbnestbreak}: breakable
                                boxes inside a breakable box\\
  \texttt{test-japanese.tex}  & Japanese classes (ltjbook, jbook,
                                ujbook)\\
  \texttt{test-tagging.tex}   & the tests above with
                                \verb|\DocumentMetadata{tagging=on}|;\\
                              & \texttt{test-tagging.lua} checks that
                                each \texttt{FENote} follows\\
                              & its \texttt{Lbl} in the structure tree\\
  \texttt{test-tate.tex}      & \texttt{test-basic.tex} and the
                                breakable tests in tate\\
                              & (tarticle, utarticle, ltjtarticle)\\
  \texttt{test-nosplit.tex}   & with \pkg{footnotenosplit}: footnotes
                                that \TeX{} moves to the next page\\
  \texttt{test-errors.tex}    & the error messages\\
  \hline
\end{tabular}
\end{center}
\texttt{test-basic.tex} and \texttt{test-breakable-long.tex} are also
run, without and with tagging, with code around \cs{@footnotetext} that
sets the footnotes of the page in another width.  With
\pkg{footnotenosplit}, \texttt{test-common.tex} also checks that no
page has a footnote rule without a footnote and that the first footnote
below the rule is as far from the rule on every page
(\texttt{TPF-RULE OK}); \texttt{test-basic.tex},
\texttt{test-hyperref.tex}, \texttt{test-breakable-long.tex} and
\texttt{test-nested.tex} are run in this way as well.
The breakable tests are also run with the key only from
\verb|\tcbset{page footnote}| (the tests named \texttt{*-global}).

\section{History}

\begin{description}
\item[v1.8 (2026/12/04)] A box from which a footnote text cannot get
  to the page has footnotes of the box, as with
  \key{page footnote=false}: a box with \key{float} (before, an
  error), and a box in a float, in a \texttt{minipage}, in a
  \cs{parbox} or in a \texttt{tcolorbox} without the key (before, the
  footnote texts were lost).  So \verb|\tcbset{page footnote}| can be
  given for a whole document.  The boxes of a \texttt{tcbraster} can
  have the key from \cs{tcbset}; before, this was the error on the
  \texttt{after} code.
\item[v1.7 (2026/12/03)] \key{page footnote} takes a value:
  \key{page footnote=false} takes the key back, for a box or, with
  \cs{tcbset}, for the boxes that follow
  (\href{https://github.com/munepi/tcbpagefootnote/issues/1}{issue~1}).
  \key{page footnote} still cannot be used with \key{float}: in a
  document with \verb|\tcbset{page footnote}|, a box that floats is
  given \key{page footnote=false}, and its footnotes are footnotes of
  the box.  Before, the value was not read, and
  \key{page footnote=false} gave the key.  A \key{breakable} box that has the key only from
  \cs{tcbset} puts each footnote text on the page of its mark when it
  is broken; before, all its footnote texts were put where the box
  ends.  A box gets the code of the key once, also with the key
  given twice.  A key that sets a hook of the box as a whole
  can come after \key{page footnote}: before, \key{after} and
  \key{after skip} were an error there, and after \key{before title},
  \key{before upper} or \key{before lower} the footnotes of that part
  were footnotes of the box.
\item[v1.6 (2026/11/25)] A footnote text that is typeset in a box and
  put into the footnote insertion later (with an engine other than
  Lua\TeX{} in a broken box, and with the new footnote code of \LaTeX)
  keeps the parameters of its insertion that the \cs{@footnotetext} of
  the page has set.  Before, with the \pkg{footnotenosplit} package,
  such a footnote that \TeX{} moved to the next page was nearer to the
  footnote rule, by \cs{footnotetopkern}, than a footnote of the body
  text.
\item[v1.5 (2026/11/24)] With Lua\LaTeX, what a part of a broken box
  leaves for its footnotes follows the \cs{count}\cs{footins} of the
  column of the part, which a package may change from column to
  column (e.g.\ \pkg{ftnright}).  With the new footnote code of
  \LaTeX, the footnote text is typeset by the \cs{@footnotetext} of
  the page: code that a package has put around it acts on the
  footnotes of a box as well.
\item[v1.4 (2026/11/22)] A \key{breakable} box that is broken across
  pages puts each footnote text on the page of its mark: with
  Lua\LaTeX{} through the new file \texttt{tcbpagefootnote.lua}, with
  the other engines through \cs{marks}.  With the
  \pkg{tcbnestbreak} package, this also holds for a breakable box with
  \key{page footnote} inside such a box.
\item[v1.3 (2026/11/17)] Vertical writing: \key{page footnote} is
  tested in tate with p\LaTeX{}, up\LaTeX{} (with \pkg{pxpgftate}) and
  Lua\TeX-ja.  The code of the package is unchanged.
\item[v1.2 (2026/11/16)] Tagged PDF: with the new footnote code of
  \LaTeX, the footnote text is typeset at its mark and output after the
  box, so that its \texttt{FENote} follows the \texttt{Lbl} of its mark
  (\href{https://github.com/latex3/tagging-project/issues/1709}{latex3/tagging-project\#1709}).
\item[v1.1 (2026/11/14)] With \pkg{hyperref}, a \cs{footnotetext}
  after a box for a \cs{footnotemark} in the box gets the anchor of its
  mark: the mark and the anchor of the last footnote are restored after
  the footnotes of the box are put.
\item[v1.0 (2026/10/25)] First public release.
\end{description}

\section{License}

This package is licensed under the conditions of the \LaTeX{} Project
Public License, either version 1.3c of this license or (at your
option) any later version.  The latest version of this license is in
\url{https://www.latex-project.org/lppl.txt}.

\medskip
\noindent
Copyright \copyright{} 2026 Munehiro Yamamoto

\end{document}
