2

I'm currently trying to create a list of theorems using the tcolorbox package (see this overleaf document). I use the following code to set up a theorem box:

\usepackage{tcolorbox}
\tcbuselibrary{listings,theorems,breakable}
\newtcbtheorem[auto counter,number within=chapter,list inside={th}]{theorem}{Theorem}%
{colback=black!5,colframe=black!25!gray,fonttitle=\bfseries, breakable}{th}

I then create a list of theorems:

    \tcblistof[\section*]{th}{List of Theorems}

And add several theorems to my text using the following syntax:

\begin{theorem}{Famous theorem \footnote{Created by Einstein.}}{famous_theorem}
\begin{equation}
    E= m c^2
\end{equation}
\end{theorem}

This, however, throws several errors, since the tcolorbox package does not know what to do with the footnote found in the theorem title. I looked in the documentation, but I was not yet able to find a way to create a short title for the theorem that does not contain the footnote. My question is; therefore, whether it is possible to set a short title for a tcolorbox similar as can be done for figures using the caption command.

What I already tried

I tried adding a caption with a short title, but this does not seem to work since the colorbox is a float. I also tried the following syntax:

\begin{theorem}[title={[Short title.]{Long title \footnoote{test}}}]{A famous theorem \footnote{A footnote.}}{famous_theorem}
    \begin{equation}
        E= m c^2
    \end{equation}
\end{theorem}

but this does not give a correct title and still throws errors.

3
  • 1
    The list text option can be used to set a short title for the TOC. However, using \footnote still will cause errors, because the title is also used inside nameref. So, the excellent answer of @muzimuzhi Z is the best solution (I will take this proposal for the next tcolorbox version). Jul 18, 2022 at 12:10
  • Thanks for your comment! I have no problems with the list text commands. Your example in T-F-S/tcolorbox#186 seems to work perfectly with Latex2022 and the XeLatex compiler. Maybe the problem only exists with certain latex versions and compilers.
    – rickstaa
    Jul 18, 2022 at 13:36
  • 1
    Yes, the problem only arises, if the nameref package is loaded. For some reasons, one cannot have \footntote or even \footnotemark in nameref-cited titles. Jul 19, 2022 at 7:45

1 Answer 1

2

As of tcolorbox v5.1.1 (2022/06/24), there's no support for (per box or per theorem) short titles. Thus I opened a feature request in tcolorbox's repo, see T-F-S/tcolorbox#186.

Combining my attempt (see the feature request) and tricks for footnotes:

\documentclass{report} % to allow `number within=chapter`
\usepackage{tcolorbox}
\tcbuselibrary{breakable, hooks, theorems,}

\ExplSyntaxOn
% case 2, tcb theorem

% Syntax of theorem envs to be created
%   \begin{<thmname>}[<options>]{<title>}{<label>}
%   \begin{<thmname>}[<options>][<short title>]{<title>}{<label>} <<< new
%   \begin{<thmname>*}{<title>}{<label>}
\NewDocumentCommand \NewTcbTheorem {}
  {
    % "x" stands for xparse (actually latex kernel uses `ltcmd.dtx`)
    \__tcobox_new_tcbtheorem_x:w \NewTColorBox
  }
% and its Declare..., Renew..., and Provide... variants

\NewDocumentCommand \__tcobox_new_tcbtheorem_x:w { m O{} m m +m m }
  {
    #1 [auto~counter,#2] {#3} { +O{} +o +m m }
      {
        #5,
        title      = {\__tcobox_theo_title:nnn{#4}{\thetcbcounter}{##3}},
        IfValueTF  = {##2}
          { % short title is given
            list~entry = {\protect\numberline{\thetcbcounter}##2},
            nameref    = {##2},
          }
          {
            list~entry = {\protect\numberline{\thetcbcounter}##3},
            nameref    = {##3},
          },
        theo@label = {#6}{##4},
        ##1
      }
    #1 [#2,no~counter,list~inside=] {#3*} { +O{} +m }
      {
        #5,
        title = {\__tcobox_theo_title:nnn{#4}{}{##2}},
        ##1
      }
  }
\ExplSyntaxOff

\begin{document}
\tcblistof[\section*]{th}{List of Theorems}

\chapter{}

\NewTcbTheorem[auto counter, number within=chapter, list inside={th}]
  {theorem}
  {Theorem}
  {colback=black!5, colframe=black!25!gray, fonttitle=\bfseries, breakable}
  {th}

% Syntax:
%   \begin{theorem}[options]{title}{label}
%   \begin{theorem}[options][short title]{title}{label} <<< new syntax
%   \begin{theorem*}{title}{label}

Text\footnote{dummy footnote}.

\begin{theorem}{Famous theorem looong title}{famous_theorem}
  \begin{equation}
      E= m c^2
  \end{equation}
\end{theorem}

\begin{theorem}[][Famous theorem short title]{Famous theorem looong title\footnote{Created by Einstein.}}{famous_theorem2}
  Footnote is placed at end of title.
  \begin{equation}
      E= m c^2
  \end{equation}
\end{theorem}

\begin{theorem}[][Famous theorem short title]{Famous theorem looong title\textsuperscript{$a$}}{famous_theorem3}
  Footnote is placed at end of current box.
  \begin{equation}
      E= m c^2
  \end{equation}
  \footnotetext[1]{Created by Einstein.}
\end{theorem}

% option `after app` needs tcb library `hooks`
\begin{theorem}[after pre=\footnotetext{Created by Einstein.}][Famous theorem short title]{Famous theorem looong title\footnotemark}{famous_theorem3}
  Footnote is placed at end of current page.
  \begin{equation}
      E= m c^2
  \end{equation}
\end{theorem}

Text\footnote{another dummy footnote}.
\end{document}

list of theorems theorems

3
  • I can't thank you enough for explaining the current behaviour, providing me with the correct expl3 code and creating the feature request. The code is very easy to read and solves all my problems. You are a true hero!
    – rickstaa
    Jul 17, 2022 at 18:26
  • 1
    Just a small correction: Use +O{} +m for the starred environment version instead of +m m Jul 18, 2022 at 12:12
  • @ThomasF.Sturm Corrected both here and in the github issue. Thank you! Jul 18, 2022 at 17:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .