thmtools icon indicating copy to clipboard operation
thmtools copied to clipboard

\listoftheorems: hide title

Open muzimuzhi opened this issue 4 years ago • 1 comments

Some filtering requirements cannot be accomplished by single call of \listoftheorems. For example, list of axioms followed by list of named theorems. But multiple \listoftheorems will produce multiple titles.

muzimuzhi avatar Aug 01 '20 18:08 muzimuzhi

A naive try: if the key notitle is given to \listoftheorems, just call \@starttoc{lof} instead of \listoffigures. This is clearly problematic since it depends on how the class defines \listoffigures. For example, adjustments must be made for the AMS classes and the book class in twocolumn mode. But these limitations could be mitigated/documented.

\documentclass{article}

\usepackage{amsthm} 
\usepackage{thmtools}

\makeatletter
\newif\ifthmt@listhastitle
\thmt@listhastitletrue
\define@key{thmt-listof}{notitle}[true]{\thmt@listhastitlefalse}

\renewcommand\listoftheorems[1][]{%
  %% much hacking here to pick up the definition from the class
  %% without oodles of conditionals.
  \begingroup
  \setlisttheoremstyle{#1}%
  \let\listfigurename\listtheoremname
  \def\contentsline##1{%
    \csname thmt@contentsline@##1\endcsname{##1}%
  }%
  \@for\thmt@envname:=\thmt@allenvs\do{%
    % CHECK: is \cs{l@\thmt@envname} repeatedly defined?
    \thmtlo@newentry
  }%
  \let\thref@starttoc\@starttoc
  \def\@starttoc##1{\thref@starttoc{loe}}%
  % new hack: to allow multiple calls, we defer the opening of the
  % loe file to AtEndDocument time. This is before the aux file is
  % read back again, that is early enough.
  % TODO: is it? crosscheck include/includeonly!
  \@fileswfalse
  \AtEndDocument{%
    \if@filesw
      \@ifundefined{tf@loe}{%
        \expandafter\newwrite\csname tf@loe\endcsname
        \immediate\openout \csname tf@loe\endcsname \jobname.loe\relax
      }{}%
    \fi
  }%
  %\expandafter
  \ifthmt@listhastitle
    \listoffigures%
  \else
    \@starttoc{lof}%
  \fi
  \endgroup
}
\makeatother

\declaretheorem{axiom}
\declaretheorem{theorem}

\begin{document}

\listoftheorems[ignoreall,show=axiom]
\listoftheorems[ignoreall,show=theorem,notitle]
     
\begin{axiom}
some axiom
\end{axiom}

\begin{theorem}
some theorem
\end{theorem}

\begin{axiom}
another axiom
\end{axiom}

\begin{theorem}
another theorem
\end{theorem}

\end{document}

tempfile-1

mbertucci47 avatar Nov 12 '23 02:11 mbertucci47