TransWikia.com

Safe footnotemarks and automatically call footnotetext with tcolorbox

TeX - LaTeX Asked by Manuel Schmidt on November 11, 2020

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
letsidenotemarkfootnotemark
NewDocumentCommandsidenotetext{om}{%
    IfValueTF{#1}%
    {@footnotetext[#1]{#2}}%
    {footnotetext{#2}}%
}

begin{document}
    begin{TcbTheorem}{Name}{ref}
        Testsidenotemark

        Anothersidenotemark
    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.

2 Answers

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}

lettuftenote=marginnote
letmarginnoterelax% make compatible
usepackage{marginnote}
letauxmarginpar=marginnote
letmarginnote=tuftenote% restore original

makeatletter
let@sidenotemark@footnotemark
let@sidenotetext@footnotetext
%
longdef@tufte@sidenote[#1][#2]#3{%
  ifthenelse{boolean{@tufte@loadnatbib}}{%
    letcite@tufte@infootnote@cite%   use the in-sidenote cite command
  }{}%
  gdef@tufte@citations{}%           clear out any old citations
  ifthenelse{NOTisempty{#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@@mpfnendcsname #1relax%
      unrestored@protected@xdef@thefnmark{thempfn}%
    endgroup%
    @sidenotemark@sidenotetext[@tufte@sidenote@vertical@offset]{#3}%
  }%
  @tufte@print@citations%            print any citations
  ifthenelse{boolean{@tufte@loadnatbib}}{%
    letcite@tufte@normal@cite%       go back to using normal in-text cite command
  }{}%
  unskipignorespaces%               remove extra white space
  kern-multiplefootnotemarker%      remove kern left behind by sidenote
  kernmultiplefootnotemarkerrelax% add new kern here to replace the one we yanked
}
newcommand{TCBsidenote}{def@mpfn{footnote}% setup
  letthempfn=thefootnote
  letmarginpar=auxmarginpar}
makeatother

begin{document}
    begin{TcbTheorem}{Name}{ref}
      TCBsidenote% local setup
        Testsidenote{First}

        Anothersidenote{Second}
    end{TcbTheorem}

end{document}

Answered by John Kormylo on November 11, 2020

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

RequirePackage{xparse}
RequirePackage{etoolbox}

def@me@blocknotemarks@keys@add#1#2{expandafterxdefcsname @me@blocknotemarks@keys@#1endcsname{#2}}
def@me@blocknotemarks@keys@get#1{csname @me@blocknotemarks@keys@#1endcsname}

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 Absidenote{Aa}
        item Bbsidenote[3cm]{Bb}
        item bmarginnote[5cm]{foo}
    end{itemize}
end{TcbTheorem}
end{document}

Answered by Manuel Schmidt on November 11, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP