TransWikia.com

Redefining List of Theorems from thmtools to get Envname Number instead of Number

TeX - LaTeX Asked by Níckolas Alves on April 7, 2021

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}

letoldnumberlinenumberline%
renewcommand{numberline}[1][negmedspace]{#1 oldnumberline}
makeatletter
@forthmt@envname:=thmt@allenvsdo{ 
    defll@envname{%
            protectnumberline[thmt@thmname]{csname thethmt@envnameendcsname}%
            ifx@emptythmt@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}

letoldnumberlinenumberline%
renewcommand{numberline}[1][negmedspace]{#1 oldnumberline}
makeatletter
defll@definition{%
        protectnumberline[thmt@thmname]{csname thethmt@envnameendcsname}%
        ifx@emptythmt@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

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
newififthmt@listswap
defthmt@TRUE{true}
defthmt@FALSE{false}
define@key{thmt-listof}{swapnumber}[true]{%
  defthmt@tmp{#1}%
  ifxthmt@tmpthmt@TRUE
    thmt@listswaptrue
  elseifxthmt@tmpthmt@FALSE
    thmt@listswapfalse
  else
    PackageError{thmtools}{Unknown value `#1' to key swapnumber}{}%
  fifi
}

% patch for unnumbered theorem
xpatchcmdthmt@mklistcmd
  {protectnumberline{protectletprotectautodotprotect@empty}}
  {%
    protectifthmt@listswap
    protectelse
      protectnumberline{protectletprotectautodotprotect@empty}%
    protectfi
  }
  {}{fail}

% patch for numbered theorem
xpatchcmdthmt@mklistcmd
  {%
    protectnumberline{csname thethmt@envnameendcsname}%
    thmt@thmname
  }
  {%
    protectifthmt@listswap
      thmt@thmname~csname thethmt@envnameendcsname
    protectelse
      protectnumberline{csname thethmt@envnameendcsname}%
      thmt@thmname
    protectfi
  }
  {}{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

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

enter image description here

Correct answer by muzimuzhi Z on April 7, 2021

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}

letoldnumberlinenumberline%
renewcommand{numberline}[1][negmedspace]{#1 oldnumberline}
makeatletter
@forthmt@envname:=thmt@allenvsdo{ 
    @xadefcsname ll@thmt@envnameendcsname{%
            protectnumberline[thmt@thmname]{csname thethmt@envnameendcsname}%
            ifx@emptythmt@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}

Answered by Níckolas Alves on April 7, 2021

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