# How to generate a list of all definitions made in a theorem environment?

I'm currently defining terms in a note-taking document (article class) using

\newtheorem{mydef}{Definition}


in the preamble, and defining the terms within

\begin{mydef}
\textbf{Term} is ...
\endmydef}


I wonder if there's a straightforward way I can create a list of definitions comparable to what is generated by

\tableofcontents


using a similar, custom command? A contents-style list of all definitions would be helpful, and so would a command which reprints all of the definitions from throughout the document made in the mydef theorem environment.

• – John Kormylo Apr 30 '18 at 20:28
• Welcome to TeX.SX! Can you please expand the code snippets that you have posted to a full minimal working example. A MWE should compile and be as small as possible to demonstrate your problem. it's much easier to help you if we have full working code to start from. – user30471 Apr 30 '18 at 21:50
• see here tex.stackexchange.com/questions/151442/… is does what you want with just one line of \listoftheorems – Carina Chen Sep 14 '20 at 21:00

## 1 Answer

Perhaps something like this?

I have used the tocloft package to create a new "table of definitions" with the commands:

\usepackage{tocloft}
\newcommand{\listdefinitionsname}{List of definitions}
\newlistof{definitions}{dfn}{\listdefinitionsname}


I have then defined a new environment defn that will add a line to the "table of definitions" the first time \textbf{...} is used in the environment. This is done by changing the definition of \textbf to be

  \addcontentsline{dfn}{section}{\protect\numberline{\thedefinition}#1}%
\realtextbf{#1}%


inside a defn environment. Arguably a better way to do this would be to define a new command, say \mydefn, like:

\newcommand\mydefn[1]{\textbf{#1}%
\addcontentsline{dfn}{section}{\protect\numberline{\thedefinition}#1}}


but I was trying to be faithful to the code snippets in the OP.

Here is the full code:

\documentclass{article}
\usepackage{tocloft}
\newcommand{\listdefinitionsname}{List of definitions}
\newlistof{definitions}{dfn}{\listdefinitionsname}

% create the new definition environment
\newtheorem{definition}{Definition}
\usepackage{etoolbox}

% an enhanced version of \textbf that adds an entry to list of defs
\let\realtextbf\textbf
\newcommand\answertextbf[1]{%
\addcontentsline{dfn}{section}{\protect\numberline{\thedefinition}#1}%
\realtextbf{#1}%
\let\textbf\real\textbf% reset \textbf to normal
}
\usepackage{xparse}
\NewDocumentEnvironment{defn}{o}{
\let\textbf\answertextbf
\IfNoValueTF{#1}{\definition}{\definition[#1]}
}{\enddefinition}

\begin{document}
\listofdefinitions

\begin{defn}
\textbf{Term 1} is ...
\end{defn}

\begin{defn}[Hi]
\textbf{Term 2} is ...
\end{defn}

\end{document}