Changing content of \listoftheorems and hyperlinking to text

Here's my MWE:

\documentclass{report}
\usepackage{amsthm}
\usepackage{libertine} % allows bf sc fonts http://tex.stackexchange.com/a/98581/104449
\usepackage{thmtools}

\declaretheoremstyle[
spaceabove=\topsep, spacebelow=\topsep,
notefont=\libertine\bfseries\scshape,
numberwithin=chapter,
notebraces={- }{}
]{mythmstyle}
\declaretheorem[style=mythmstyle]{thm}
\declaretheorem[style=mythmstyle, title=Defn]{defn}

\begin{document}
\pagenumbering{roman}

\listoftheorems[ignoreall, show={thm}]
\begingroup               % Temporarily disable \clearpage to show both lists on one page
\let\clearpage\relax    % http://tex.stackexchange.com/a/14511/104449
\renewcommand{\listtheoremname}{List of Definitions}
\listoftheorems[ignoreall, show={defn}]
\endgroup

\newpage
\pagenumbering{arabic}
\chapter{}
\begin{thm}[My first theorem]
\end{thm}

\begin{defn}[My first definition]
\end{defn}

\chapter{}
\begin{thm}[My second theorem]
\end{thm}

\begin{defn}[My second definition]
\end{defn}

\end{document}


Here's what the output of this looks like:

I want to get rid of the Thm/Defn prefixes and the enclosing parenthesis for each entry in List of Theorems and List of Definitions. i.e. I'd like the first entry to be like:

1.1 My first theorem ...................................... 1


I also want the entries in the list to hyperlink to the page (and ideally the exact location) of the referenced theorem/definition.

Does anybody know how to do this or have tips on what documentation to read? I looked at thmtools documentation for \listotheorems but I was unable to figure out how to change the content of each line entry.

• I think this is hardcoded in thm-listof.sty, but I'll take a look – user31729 May 1 '16 at 19:25

The name={...} option to the definition in the \declaretheoremstyle command defaults to the theorem name, or it's possible to say name={} to remove the prefix in the List of Theorems, but this has an effect to the body-text display as well. (It's not the best solution)

The parentheses can be removed by redefining \thmtformatoptarg to be

\renewcommand{\thmtformatoptarg}[1]{#1}


Loading hyperref as the last package provides the correct links.

\documentclass{report}
\usepackage{amsthm}
\usepackage{libertine} % allows bf sc fonts http://tex.stackexchange.com/a/98581/104449
\usepackage{thmtools}

\declaretheoremstyle[
spaceabove=\topsep, spacebelow=\topsep,
notefont=\libertine\bfseries\scshape,
numberwithin=chapter,
notebraces={- }{}
]{mythmstyle}
\declaretheorem[style=mythmstyle,name={}]{thm}
\declaretheorem[style=mythmstyle, title=Defn,name={}]{defn}

\renewcommand{\thmtformatoptarg}[1]{#1}%

\usepackage{hyperref}

\begin{document}
\pagenumbering{roman}

\listoftheorems[ignoreall, show={thm}]
\begingroup               % Temporarily disable \clearpage to show both lists on one page
\let\clearpage\relax    % http://tex.stackexchange.com/a/14511/104449
\renewcommand{\listtheoremname}{List of Definitions}
\listoftheorems[ignoreall, show={defn}]
\endgroup

\newpage
\pagenumbering{arabic}
\chapter{}
\begin{thm}[My first theorem]
\end{thm}

\begin{defn}[My first definition]
\end{defn}

\chapter{}
\begin{thm}[My second theorem]
\end{thm}

\begin{defn}[My second definition]
\end{defn}

\end{document}


Update

The \thmt@thmname is inside \thmt@mklistcmd which is only called once during a theorem definition. If the name isn't requested, it should be dropped. Either patch the \thmt@mklistcmd or redefine it:

\documentclass{report}
\usepackage{amsthm}
\usepackage{libertine} % allows bf sc fonts http://tex.stackexchange.com/a/98581/104449
\usepackage{thmtools}

\newif\ifusethmname

\makeatletter

\renewcommand\thmt@mklistcmd{%
\@xa\protected@edef\csname l@\thmt@envname\endcsname{% CHECK: why p@edef?
\@nx\@dottedtocline{1}{1.5em}{\@nx\thmt@listnumwidth}%
}%
\ifthmt@isstarred
\@xa\def\csname ll@\thmt@envname\endcsname{%
\protect\numberline{\protect\let\protect\autodot\protect\@empty}%
\ifusethmname
\thmt@thmname
\fi
\ifx\@empty\thmt@shortoptarg\else\protect\thmtformatoptarg{\thmt@shortoptarg}\fi
}%
\else
\@xa\def\csname ll@\thmt@envname\endcsname{%
\protect\numberline{\csname the\thmt@envname\endcsname}%
\ifusethmname
\thmt@thmname
\fi
\ifx\@empty\thmt@shortoptarg\else\protect\thmtformatoptarg{\thmt@shortoptarg}\fi
}%
\fi
\@xa\gdef\csname thmt@contentsline@\thmt@envname\endcsname{%
\thmt@contentslineShow% default:show
}%
}

\declaretheoremstyle[
spaceabove=\topsep, spacebelow=\topsep,
notefont=\libertine\bfseries\scshape,
numberwithin=chapter,
notebraces={- }{}
]{mythmstyle}
\declaretheorem[style=mythmstyle, ]{thm}
\declaretheorem[style=mythmstyle, title=Defn]{defn}

\usepackage{xpatch}

\renewcommand{\thmtformatoptarg}[1]{#1}%

\usepackage{hyperref}

\begin{document}
\pagenumbering{roman}

\makeatletter

\makeatother
\listoftheorems[ignoreall, show={thm}]
\begingroup               % Temporarily disable \clearpage to show both lists on one page
\let\clearpage\relax    % http://tex.stackexchange.com/a/14511/104449
\renewcommand{\listtheoremname}{List of Definitions}
\listoftheorems[ignoreall, show={defn}]
\endgroup

\newpage
\pagenumbering{arabic}
\chapter{}
\begin{thm}[My first theorem]
\end{thm}

\begin{defn}[My first definition]
\end{defn}

\chapter{}
\begin{thm}[My second theorem]
\end{thm}

\begin{defn}[My second definition]
\end{defn}

\end{document}


• Thanks! That worked nicely. Can you explain what you mean by "this has an effect to the body-text display as well"? I put in your changes, and I don't see any discernible changes in how the body text is being displayed. – Synergist May 1 '16 at 20:15
• @Synergist: The abbreviation Thm vanishes also in the body, i.e. where the Theorem really is displayed. I try to remove this 'unpleasant' feature! – user31729 May 1 '16 at 20:17
• @Synergist: I've found the 'error' using the Thm and Defn prefixes in the List of ... -- see the update please, – user31729 May 1 '16 at 20:48
• Wow, thank you! I just started using LaTeX a few months ago. So some of what you did is beyond my current scope. In particular, I have no experience with patching commands like you did. If it's not a bother, would you mind briefly explaining how you were able to track down that \thmt@thmname is inside \thmt@mklistcmd? – Synergist May 1 '16 at 21:01
• @Synergist: Of course I had to look into the code of thmtools, especially thm-listof.sty. Basically, any List of... uses \addcontentsline → look for this code and trace back, here the ll@.... command which does the real display and spacings is of interest -- there I found \thmt@thmname to be the 'villain'. But it took some minutes to understand that \thmt@mklistcmd` had to be changed before the definitions of the theorems, definitions etc. occur! – user31729 May 1 '16 at 21:06