%% 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.5 (2026/11/24)}
\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
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{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' cannot be used with 'float'.}]
  A floating box (\key{float}) is not followed by the code that puts the
  footnotes.
\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.  Keys that set the whole \texttt{after} code
  (such as \key{after}, \key{after skip} and \key{nobeforeafter}) remove it
  when they come after \key{page footnote}: give them before it, e.g.\
  \verb|[after skip=1pt, page footnote]|.
\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} or inside another box; see below.
\end{description}

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

\begin{itemize}
\item In a \texttt{multicols} environment, where the footnotes are
  below all the columns, and inside another box such as a
  \texttt{minipage}, 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 \key{page footnote} cannot be used with \key{float}.
\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.
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-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-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.

\section{History}

\begin{description}
\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 any later
version.

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

\end{document}
