带有可破坏的 tcolorbox 的脚注

带有可破坏的 tcolorbox 的脚注

我正在尝试只使用一个全局脚注系统(编号),但我似乎对易碎的 tcolorboxes 有一些问题。我读过的许多答案似乎对于我对单一全局脚注系统的简单要求来说太高级了。

我的序言是

\documentclass[a4paper,10pt,titlepage]{article}
\usepackage[utf8]{inputenc}
\newcommand{\myparagraph}[1]{\paragraph{#1}\mbox{}\\}
\usepackage[a4paper,margin=3.5cm]{geometry} %Sets the page geometry
\usepackage{url}
\usepackage{dirtytalk}
\usepackage{graphicx} % Package for \includegraphics
\usepackage{wrapfig} % Figure wrapping
\usepackage[T1]{fontenc} % Output font encoding for international characters
\setlength{\parskip}{1em} % Set space when paragraphs are used
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{hyperref}
\usepackage{mathrsfs}
\usepackage{mdframed}
\usepackage[breakable]{tcolorbox}
\usepackage[justification=centering]{caption}
\usepackage{soul}

% Note that we enforce things so that everything is numbered off of theorems
\theoremstyle{definition} % to avoid italicizing theorems
\newmdtheoremenv{theo}{Theorem}
\newtheorem{thm}{Theorem}[section] % reset theorem numbering for each chapter
\newtheorem{defn}[thm]{Definition} % definition numbers are dependent on theorem numbers
\newtheorem{rmk}[thm]{Remark}
\newtheorem{exmp}[thm]{Example} % same for example numbers
\newtheorem{crlry}[thm]{Corollary}
\newtheorem{lemma}[thm]{Lemma}
\newtheorem{problem}{Problem}[section]

%% HOW TO KEEP FOOTNOTES GLOBAL
\usepackage{footnote}
\usepackage{etoolbox}
\BeforeBeginEnvironment{tcolorbox}{\savenotes}
\AfterEndEnvironment{tcolorbox}{\spewnotes}
\usepackage{blindtext}

\usepackage{geometry}
    %\usepackage{showframe} %This line can be used to clearly show the new margins

\newgeometry{vmargin={25mm}, hmargin={22mm,22mm}}

% Lets you use \blankpage to make a blank page
\newcommand{\blankpage}{
\newpage
\thispagestyle{empty}
\mbox{}
\newpage
}

我的脚注示例如下:

\begin{tcolorbox}[breakable]
\begin{defn}[Equivalence class]
    Given an equivalence relation $\equiv$ defined on a set $S$, we define the equivalence class corresponding to any $a \in S$ as the set\footnote{If the equivalence relation in question is understood from context we'll sometimes just write $[a]$.}
    $$[a]_\equiv = \{ b \in S | a \equiv B \}$$
\end{defn}
\end{tcolorbox}

下图显示了我的问题示例(请注意两个 tcolorbox,每个都以脚注“a”开头)。不过,我在 tcolorbox 之外执行的任何操作都没有问题,并且是全局的,并且增量正确。

在此处输入图片描述

任何帮助都将不胜感激,谢谢!

答案1

请注意,这将\BeforeBeginEnvironment和结合起来\renewenvironment。它与在可选参数之前或之后执行命令有关。

\documentclass[a4paper,10pt,titlepage]{article}
\usepackage[utf8]{inputenc}
\newcommand{\myparagraph}[1]{\paragraph{#1}\mbox{}\\}
\usepackage[a4paper,margin=3.5cm]{geometry} %Sets the page geometry
\geometry{vmargin={25mm}, hmargin={22mm,22mm}}

\usepackage{url}
%\usepackage{dirtytalk}
\usepackage{graphicx} % Package for \includegraphics
\usepackage{wrapfig} % Figure wrapping
\usepackage[T1]{fontenc} % Output font encoding for international characters
\setlength{\parskip}{1em} % Set space when paragraphs are used
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{mathrsfs}
\usepackage{mdframed}
\usepackage[justification=centering]{caption}
\usepackage{soul}

% Note that we enforce things so that everything is numbered off of theorems
\theoremstyle{definition} % to avoid italicizing theorems
\newmdtheoremenv{theo}{Theorem}
\newtheorem{thm}{Theorem}[section] % reset theorem numbering for each chapter
\newtheorem{defn}[thm]{Definition} % definition numbers are dependent on theorem numbers
\newtheorem{rmk}[thm]{Remark}
\newtheorem{exmp}[thm]{Example} % same for example numbers
\newtheorem{crlry}[thm]{Corollary}
\newtheorem{lemma}[thm]{Lemma}
\newtheorem{problem}{Problem}[section]

%% HOW TO KEEP FOOTNOTES GLOBAL
\usepackage[breakable]{tcolorbox}
\usepackage{footnote}
\BeforeBeginEnvironment{tcolorbox}{\savenotes}
\AfterEndEnvironment{tcolorbox}{\spewnotes}
\makeatletter
\let\oldtcolorbox=\tcolorbox
\let\endoldtcolorbox=\endtcolorbox
\renewenvironment{tcolorbox}[1][]{\oldtcolorbox[#1]%
  \def\@mpfn{footnote}%
  \def\thempfn{\thefootnote}}%
{\endoldtcolorbox}
\makeatother

\usepackage{hyperref}

% Lets you use \blankpage to make a blank page
\newcommand{\blankpage}{
\newpage
\thispagestyle{empty}
\mbox{}
\newpage
}
\begin{document}
Test\footnote{First}

\begin{tcolorbox}[breakable]
\begin{defn}[Equivalence class]
    Given an equivalence relation $\equiv$ defined on a set $S$, we define the equivalence class corresponding to any $a \in S$ as the set\footnote{If the equivalence relation in question is understood from context we'll sometimes just write $[a]$.}
    $$[a]_\equiv = \{ b \in S | a \equiv B \}$$
\end{defn}
\end{tcolorbox}
\end{document}

相关内容