0

I am trying to use tcolorbox with tufte-book. The known problem is, that tufte's floating sidenotes are not working with tcolorx theorems. I have the following workaround:

\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}

Is it possible to automate the calls to \sidenotetext at the end of the theorem?

I guess this requires to save everything in a list.

  • Apparently tufte uses \@tufte@sidenote for both footnotes and sidenotes, if if one doesn't work for one, it won't work for the other. – John Kormylo May 28 at 11:40
  • My MWE is a workaround for this problem. I just want to make it automated. – Manuel Schmidt May 28 at 11:46
  • Tufte \@footnotetext uses \marginpar. You could probably use the marginnote package. OTOH I see that tcolobox and tufte both use \@mpfn to contain the counter name for footnotes. – John Kormylo May 28 at 12:02
  • I tried the marginpar package. It has strange effects. Therefore my workaround above. – Manuel Schmidt May 28 at 12:16
0

The idea is to replace \marginpar with \marginnote (marginnote package), but only inside tcolorbox. The biggest problem with \marginnote is that the notes tends to overlap.

\TCBsidenote also uses the global footnote counter instead of 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}
| improve this answer | |
0

I got it working. The following does what I want:

\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}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.