2

I want to use the example environment that was suggested by @Jonathan in the related post. This is almost the same MWE:

\documentclass{article}
\usepackage[most]{tcolorbox}
\newcounter{testexample}
\usepackage{xparse}
\usepackage{lipsum}
\def\exampletext{Example}
\NewDocumentEnvironment{testexample}{ O{} }
{
\colorlet{colexam}{red!55!black}
\newtcolorbox[use counter=testexample]{testexamplebox}{
    empty,
    title={\exampletext: #1},
    attach boxed title to top left,
       minipage boxed title,
    boxed title style={empty,size=minimal,toprule=0pt,top=4pt,left=3mm,overlay={}},
coltitle=colexam,fonttitle=\bfseries,
before=\par\medskip\noindent,parbox=false,boxsep=0pt,left=3mm,right=0mm,top=2pt,breakable,pad at break=0mm,
   before upper=\csname @totalleftmargin\endcsname0pt,
overlay unbroken={\draw[colexam,line width=.5pt] ([xshift=-0pt]title.north west) -- ([xshift=-0pt]frame.south west); },
overlay first={\draw[colexam,line width=.5pt] ([xshift=-0pt]title.north west) -- ([xshift=-0pt]frame.south west); },
overlay middle={\draw[colexam,line width=.5pt] ([xshift=-0pt]frame.north west) -- ([xshift=-0pt]frame.south west); },
overlay last={\draw[colexam,line width=.5pt] ([xshift=-0pt]frame.north west) -- ([xshift=-0pt]frame.south west); },%
}
\begin{testexamplebox}}
{\end{testexamplebox}\endlist}

\begin{document}

\begin{testexample}[Latin Text]
\lipsum[1]\footnote{my footnote}
\lipsum[2]
\end{testexample}

\end{document}

Then, I want that \footnote made footnote at the bottom of the page not in the end of the example. I have already found this answer on the similar question but it was about using already appeared earlier footnotes. Can I do the same when \footnote only appears once in the example?

arkkus
  • 45

1 Answers1

2

Here is a way be redefining footnote inside your environment:

\documentclass{article}
\usepackage[most]{tcolorbox}
\newcounter{testexample}
\usepackage{xparse}
\usepackage{pgffor}
\usepackage{lipsum}
\newcounter{FootnoteCounter}
\newcounter{Init}
\let\oldfootnote\footnote
\def\exampletext{Example}

\NewDocumentEnvironment{testexample}{ O{} }
{
\colorlet{colexam}{red!55!black}
\newtcolorbox[use counter=testexample]{testexamplebox}{
    empty,
    title={\exampletext: #1},
    attach boxed title to top left,
       minipage boxed title,
    boxed title style={empty,size=minimal,toprule=0pt,top=4pt,left=3mm,overlay={}},
coltitle=colexam,fonttitle=\bfseries,
before=\par\medskip\noindent,parbox=false,boxsep=0pt,left=3mm,right=0mm,top=2pt,breakable,pad at break=0mm,
   before upper=\csname @totalleftmargin\endcsname0pt,
overlay unbroken={\draw[colexam,line width=.5pt] ([xshift=-0pt]title.north west) -- ([xshift=-0pt]frame.south west); },
overlay first={\draw[colexam,line width=.5pt] ([xshift=-0pt]title.north west) -- ([xshift=-0pt]frame.south west); },
overlay middle={\draw[colexam,line width=.5pt] ([xshift=-0pt]frame.north west) -- ([xshift=-0pt]frame.south west); },
overlay last={\draw[colexam,line width=.5pt] ([xshift=-0pt]frame.north west) -- ([xshift=-0pt]frame.south west); },%
}
\begin{testexamplebox}%
\setcounter{Init}{\value{footnote}}
\setcounter{FootnoteCounter}{\value{Init}}
\def\footnote##1{\stepcounter{footnote}\stepcounter{FootnoteCounter}\footnotemark[\arabic{FootnoteCounter}]\def\temp{##1}\expandafter\expandafter\expandafter\global\expandafter\let\csname F\arabic{FootnoteCounter}\endcsname\temp
}}
{\end{testexamplebox}\endlist\stepcounter{Init}\foreach \f in {\arabic{Init},...,\arabic{FootnoteCounter}}{\footnotetext[\f]{\csname F\f\endcsname}}}


\begin{document}

\begin{testexample}[Latin Text]
\lipsum[1]\footnote{my first footnote}
\lipsum[2]\footnote{Another Footnote}
\end{testexample}

A text with a footnote here\footnote{Test Outside}

\begin{testexample}[Latin Text]
\lipsum[1]\footnote{my third footnote}
\lipsum[2]\footnote{Another Footnote}
\end{testexample}

\end{document}

enter image description here

koleygr
  • 20,105
  • Thanks for the great example, +1 for multiple footnotes and boxed. Are xparse and pgffor actually used in your example? – AstroFloyd Apr 11 '22 at 12:09
  • You define a counter, but don't use it. It might be useful to rename it to e.g. examplecnt and use it as e.g. title={Example~\arabic{examplecnt}: #1},. – AstroFloyd Apr 11 '22 at 12:28
  • 1
    Thanks @AstroFloyd ... Actually if you see the OPs question this is his/her code changed ... I didn't changed the original code so that the OP can use it directly in his example and not just in this MWE – koleygr Apr 12 '22 at 13:21
  • 1
    pgffor is used in the \foreach loop ... Could be avoided by a TeX loop or alternatives. – koleygr Apr 12 '22 at 13:22
  • Thanks! I have another question. As soon as I remove all footnotes from one of the boxes, I get empty footnote markers at the bottom of the page. This only seems to work correctly if there is at least one footnote in each box. Is there a way to circumvent this, so that the Example environment can be used both with and without footnotes? – AstroFloyd Apr 12 '22 at 14:33