我正在尝试使用tcolorbox
。tufte-book
已知问题是,tufte 的浮动旁注不适用于 tcolorx 定理。我有以下解决方法:
\documentclass[10pt,a4paper]{tufte-book}
\usepackage{lipsum}
\usepackage[all]{tcolorbox}
\newtcbtheorem[number within=chapter]{TcbTheorem}{Theorem}{
colback=blue!5, colframe=blue!5, coltitle=red,
}{thm}
% sidenotemark
\let\sidenotemark\footnotemark
\NewDocumentCommand\sidenotetext{om}{%
\IfValueTF{#1}%
{\@footnotetext[#1]{#2}}%
{\footnotetext{#2}}%
}
\begin{document}
\begin{TcbTheorem}{Name}{ref}
Test\sidenotemark
Another\sidenotemark
\end{TcbTheorem}
\sidenotetext{First}
\sidenotetext{Second}
\end{document}
\sidenotetext
是否有可能自动执行定理末尾的调用?
我猜这需要将所有内容保存在列表中。
答案1
想法是\marginpar
用\marginnote
(marginnote 包)来替代,但只在 tcolorbox 内部。最大的问题\marginnote
是注释容易重叠。
\TCBsidenote
还使用全局脚注计数器而不是mpfootnote
。
\documentclass[10pt,a4paper]{tufte-book}
\usepackage{lipsum}
\usepackage[theorems]{tcolorbox}
\newtcbtheorem[number within=chapter]{TcbTheorem}{Theorem}{
colback=blue!5, colframe=blue!5, coltitle=red,
}{thm}
\let\tuftenote=\marginnote
\let\marginnote\relax% make compatible
\usepackage{marginnote}
\let\auxmarginpar=\marginnote
\let\marginnote=\tuftenote% restore original
\makeatletter
\let\@sidenotemark\@footnotemark
\let\@sidenotetext\@footnotetext
%
\long\def\@tufte@sidenote[#1][#2]#3{%
\ifthenelse{\boolean{@tufte@loadnatbib}}{%
\let\cite\@tufte@infootnote@cite% use the in-sidenote \cite command
}{}%
\gdef\@tufte@citations{}% clear out any old citations
\ifthenelse{\NOT\isempty{#2}}{%
\gsetlength{\@tufte@sidenote@vertical@offset}{#2}%
}{%
\gsetlength{\@tufte@sidenote@vertical@offset}{0pt}%
}%
\ifthenelse{\isempty{#1}}{%
% no specific footnote number provided
\stepcounter\@mpfn%
\protected@xdef\@thefnmark{\thempfn}%
\@sidenotemark\@sidenotetext[\@tufte@sidenote@vertical@offset]{#3}%
}{%
% specific footnote number provided
\begingroup%
\csname c@\@mpfn\endcsname #1\relax%
\unrestored@protected@xdef\@thefnmark{\thempfn}%
\endgroup%
\@sidenotemark\@sidenotetext[\@tufte@sidenote@vertical@offset]{#3}%
}%
\@tufte@print@citations% print any citations
\ifthenelse{\boolean{@tufte@loadnatbib}}{%
\let\cite\@tufte@normal@cite% go back to using normal in-text \cite command
}{}%
\unskip\ignorespaces% remove extra white space
\kern-\multiplefootnotemarker% remove \kern left behind by sidenote
\kern\multiplefootnotemarker\relax% add new \kern here to replace the one we yanked
}
\newcommand{\TCBsidenote}{\def\@mpfn{footnote}% setup
\let\thempfn=\thefootnote
\let\marginpar=\auxmarginpar}
\makeatother
\begin{document}
\begin{TcbTheorem}{Name}{ref}
\TCBsidenote% local setup
Test\sidenote{First}
Another\sidenote{Second}
\end{TcbTheorem}
\end{document}
答案2
我让它工作了。下面是我想要的:
\RequirePackage{xparse}
\RequirePackage{etoolbox}
\def\@me@blocknotemarks@keys@add#1#2{\expandafter\xdef\csname @me@blocknotemarks@keys@#1\endcsname{#2}}
\def\@me@blocknotemarks@keys@get#1{\csname @me@blocknotemarks@keys@#1\endcsname}
\newcounter{@me@blocknote@size}
\newcounter{@me@blocknote@iter}
\NewDocumentCommand{\bsidenotemark}{}{%
\addtocounter{@me@blocknote@size}{1}\footnotemark
\@me@blocknotemarks@keys@add{\the@me@blocknote@size}{\thefootnote}
}
\NewDocumentCommand{\bsidenotetext}{O{0pt}m}{%
\addtocounter{@me@blocknote@iter}{1}
\protected@xdef\@thefnmark{\@me@blocknotemarks@keys@get{\the@me@blocknote@iter}}%
\@footnotetext[#1]{#2}
}
\gdef\@me@blocknote@lists@pending{\relax} % create empty list
\NewDocumentCommand{\bsidenote}{O{0pt}m}{%
\bsidenotemark{}%
% will be executed by \bsidenoteprocess
\listgadd{\@me@blocknote@lists@pending}{\bsidenotetext[#1]{#2}}
}
\NewDocumentCommand{\bsidenoteprocess}{}{%
\forlistloop{}{\@me@blocknote@lists@pending}
\gdef\@me@blocknote@lists@pending{\relax} % claer list
}
\NewDocumentCommand{\bmarginnote}{O{0pt}m}{%
\listgadd{\@me@blocknote@lists@pending}{\marginnote[#1]{#2}}
}
\newtcbtheorem[number within=chapter]{TcbTheorem}{Theorem}{
colback=blue!5, colframe=blue, coltitle=blue,
after={\bsidenoteprocess},
}{thm}
\begin{document}
\begin{TcbTheorem}{}{}
\begin{itemize}
\item A\bsidenote{Aa}
\item B\bsidenote[3cm]{Bb}
\item \bmarginnote[5cm]{foo}
\end{itemize}
\end{TcbTheorem}
\end{document}