0

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.

2

Perhaps something like this?

enter image description here

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.