1

I'm trying to redefine the List of Theorems environment from thmtools to typeset a List of Theorems that looks like

Definition 1 Foo ......1

Theorem 2 ..............2

rather than the usual

1 Definition (Foo) ....1

2 Theorem ..............2

My current attempt is this MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}

\declaretheorem{theorem}
\declaretheorem[sibling=theorem]{definition}

\let\oldnumberline\numberline%
\renewcommand{\numberline}[1][\negmedspace]{#1 \oldnumberline}
\makeatletter
\@for\thmt@envname:=\thmt@allenvs\do{ 
    \def\ll@envname{%
            \protect\numberline[\thmt@thmname]{\csname the\thmt@envname\endcsname}%
            \ifx\@empty\thmt@shortoptarg%
            \else
                \thmt@shortoptarg%
            \fi
        }
}
\makeatother
\begin{document}
\section{Section}
\begin{theorem}[Named Theorem]
\end{theorem}

\begin{definition}[Named Definition]
\end{definition}

\begin{definition}
\end{definition}

\listoftheorems
\end{document}

It seems to change nothing when compared with the usual construction. I believe the problem is the the \@for loop. I guess I might be running it wrongly, or using the wrong list of environments. I tried to construct it by looking at the thmtools documentation, as I couldn't really find the \ll@envname definition on the package's code. This belief is due to the fact that the following code does precisely what I have in mind, but works only for the definition environment (and I'd like to have something that works for all, without need to copy and paste the code every time I declare a new theorem):

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}

\declaretheorem{theorem}
\declaretheorem[sibling=theorem]{definition}

\let\oldnumberline\numberline%
\renewcommand{\numberline}[1][\negmedspace]{#1 \oldnumberline}
\makeatletter
\def\ll@definition{%
        \protect\numberline[\thmt@thmname]{\csname the\thmt@envname\endcsname}%
        \ifx\@empty\thmt@shortoptarg%
        \else
            \thmt@shortoptarg%
        \fi
    }
\makeatother
\begin{document}
\section{Section}
\begin{theorem}[Named Theorem]
\end{theorem}

\begin{definition}[Named Definition]
\end{definition}

\begin{definition}
\end{definition}

\listoftheorems
\end{document}

How can I correctly state the \@for loop so that the code generalizes to all declared theorem-like environments? Alternatively, is there another way of obtaining the result I'm looking for?

2 Answers 2

1

Another approach, by providing a new \listoftheorems option swapnumber.

  • Update 1: Make boolean option swapnumber more robust.
  • Update 2: Make swapnumber compatible with unnumbered theorem.
  • Update 3: Remove parentheses around the theorem names shown in \listoftheorems, by redefining \thmtformatoptarg.
\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{xpatch}

% define new \listoftheorems option "swapnumber"
\makeatletter
\newif\ifthmt@listswap
\def\thmt@TRUE{true}
\def\thmt@FALSE{false}
\define@key{thmt-listof}{swapnumber}[true]{%
  \def\thmt@tmp{#1}%
  \ifx\thmt@tmp\thmt@TRUE
    \thmt@listswaptrue
  \else\ifx\thmt@tmp\thmt@FALSE
    \thmt@listswapfalse
  \else
    \PackageError{thmtools}{Unknown value `#1' to key swapnumber}{}%
  \fi\fi
}

% patch for unnumbered theorem
\xpatchcmd\thmt@mklistcmd
  {\protect\numberline{\protect\let\protect\autodot\protect\@empty}}
  {%
    \protect\ifthmt@listswap
    \protect\else
      \protect\numberline{\protect\let\protect\autodot\protect\@empty}%
    \protect\fi
  }
  {}{\fail}

% patch for numbered theorem
\xpatchcmd\thmt@mklistcmd
  {%
    \protect\numberline{\csname the\thmt@envname\endcsname}%
    \thmt@thmname
  }
  {%
    \protect\ifthmt@listswap
      \thmt@thmname~\csname the\thmt@envname\endcsname
    \protect\else
      \protect\numberline{\csname the\thmt@envname\endcsname}%
      \thmt@thmname
    \protect\fi
  }
  {}{\fail}
\makeatother

\declaretheorem{theorem}
\declaretheorem[sibling=theorem]{definition}
\declaretheorem[numbered=no]{axiom}

\begin{document}
\section{Section}
\begin{theorem}[Named Theorem]
\end{theorem}

\begin{definition}[Named Definition]
\end{definition}

\begin{definition}
\end{definition}

\begin{axiom}
\end{axiom}

\begin{axiom}[Named axiom]
\end{axiom}

\listoftheorems

\renewcommand\thmtformatoptarg[1]{ #1}
\listoftheorems[
  swapnumber, 
  title={List of Theorems (option \texttt{swapnumber} applied and parentheses removed)}
]
\end{document}

enter image description here

5
  • I find this approach particularly interesting because it still allows the option onlynamed to work properly. Do you think it is possible to remove the parentheses from around the names? Commented Jul 29, 2020 at 5:10
  • @NíckolasAlves You want Theorem 1 Named Theorem instead of Theorem 1 (Named Theorem)? Commented Jul 29, 2020 at 5:30
  • Yes, that's what I have in mind Commented Jul 29, 2020 at 5:39
  • @NíckolasAlves Yes it's possible. See my updated answer. Commented Jul 29, 2020 at 5:50
  • That's perfect. Thank you! Commented Jul 29, 2020 at 15:49
1

The issue was actually quite silly. I was trying to redefine \ll@envname, which is not the command I wanted to redefine. Actually, I wanted to redefine \csname ll@\thmt@envname \endcsname (which I realized when reading line 800 of thmtools' code available in the documentation). The solution is then quite simple: just correct the name of the command I'm redefining, with the proper modifications with \expandafter (which is shortened to \@xa by thmtools) and so on.

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}

\declaretheorem{theorem}
\declaretheorem[sibling=theorem]{definition}

\let\oldnumberline\numberline%
\renewcommand{\numberline}[1][\negmedspace]{#1 \oldnumberline}
\makeatletter
\@for\thmt@envname:=\thmt@allenvs\do{ 
    \@xa\def\csname ll@\thmt@envname\endcsname{%
            \protect\numberline[\thmt@thmname]{\csname the\thmt@envname\endcsname}%
            \ifx\@empty\thmt@shortoptarg%
            \else
                \thmt@shortoptarg%
            \fi
        }
}
\makeatother
\begin{document}
\section{Section}
\begin{theorem}[Named Theorem]
\end{theorem}

\begin{definition}[Named Definition]
\end{definition}

\begin{definition}
\end{definition}

\listoftheorems
\end{document}

You must log in to answer this question.

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