# List terms(/keywords) together with their definition and a glossary

I want to be able to define terms/keywords and give definitions that might span multiple paragraphs. Given definitions of the following form:

\begin{definition}[Blue]
Blue is one of ...
\end{definition}

\begin{definition}[Argument]
An argument is ...
\end{definition}


I want to be able to refer to a definition with a command (e.g. \usedef{blue}) and I want to create two separate listings, both ordered lexicographically where the one is a normal glossary index (just the keyword and referenced pages) and the other is an overview of term and definition.

The glossaries package does something to this extent, however, it lacks support for my last requirement. Also I don't know how it handles multiple paragraphs of definition. There is an optional argument called description though.

What would be a good starting point to achieve my goal, or maybe there is a package that already provides this functionality?

It would look a bit like this. (Omitting the reference in a leading text) And don't mind the fonts please.

-
I can imagine a solution using LaTeX3 especially the modul l3prop. – Marco Daniel Feb 17 '13 at 16:47
Can you add a sketch of how you'd want the various pieces of information printed? – egreg Feb 17 '13 at 17:09
@egreg I've added an example picture with some annotation – Alessandro Vermeulen Feb 17 '13 at 19:37
What should the output of \usedef{<id>} be? – clemens Feb 17 '13 at 22:10
\usedef{<id>} should print the name and link it to the definition. – Alessandro Vermeulen Feb 18 '13 at 12:49

## Combining etoc and glossaries

In my original answer (see below) I defined a custom environment for the definitions and used etoc to create a table of definitions (ToD) for them. However, since basically the task is to have the functionality of glossaries plus the ToD a better idea is to use glossaries for all its handy functionality and use etoc additionally for the ToD. The easiest way for this is to copy the \listofdefinitions from my original answer and define a custom glossary style that clones one of the predefined styles and adds the contents line for etoc. This way entries a sorted using glossaries' possibilities, i.e. either through makeindex or through xindy. Entries can be linked to through all the commands glossaries has to offer, e.g. the standard \gls{<label>}.

The code blow gives this:

\documentclass{article}
\usepackage{parskip}

\usepackage{etoc}

\usepackage[nopostdot,numberedsection]{glossaries}
\makeglossaries

\newglossarystyle{mylist}{%
\glossarystyle{list}% base this style on the list style
\renewcommand\glossaryentryfield[5]{%
% #1: label
% #2: name
% #3: description
% #4: symbol
% #5: page number(s)
\etoctoccontentsline{definition}{\protect\numberline{##2}}%
\item[\glsentryitem{##1}\glstarget{##1}{##2}] ##3\glspostdescription\space##5
}%
}

% this will display all definitions but nothing else as a toc:
\newcommand\listofdefinitions{%
\setcounter{tocdepth}{1}%
\etocsetlevel{definition}{1}% 'definition' entries will be included
\etocsetlevel{section}{2}%  % sections are hidden
\etocsettocstyle{\section{Foo}}{}%
\etocsetstyle{definition}
{}{}
{\pagebreak[2]\vskip\baselineskip}%
\tableofcontents
}

% use standard toc and hide definition entries
\etocsetlevel{definition}{6}

% dummy text:
\usepackage{lipsum}

% define entries:
\newglossaryentry{foo}{
name = Foo ,
description = \lipsum*[1]
}
\newglossaryentry{bar}{
name = Foo Bar ,
description = \lipsum*[1-2]
}
\newglossaryentry{blue}{
name = Blue ,
description = \lipsum*[1]
}
\newglossaryentry{argument}{
name = Argument ,
description = \lipsum*[1]
}

\begin{document}

\tableofcontents

\section{Foo Bar}
\subsection{Foo}
\lipsum[1]

\subsection{Bar}
\lipsum[2-4]

\gls{blue} and \gls{foo} and \gls{bar} and \gls{argument}

\appendix
\listofdefinitions

\renewcommand\glossaryname{Own name}
\glossarystyle{mylist}
\printglossaries

\end{document}


The picture reminds me somehow of jfbu's answer to »The numbering of exercises automatically on table« and I thought this seems to be a similar task. So below you see the result of my first use of etoc...

I define a simple definition environment:

\newcounter{definition}
\newenvironment{definition}[1]
{%
\refstepcounter{definition}%
\etoctoccontentsline{definition}{\protect\numberline{#1}}%
}
{\par\bigskip}


and a command \listofdefinitions that outputs the »definitions toc«:

\newcommand\listofdefinitions{%
\setcounter{tocdepth}{1}%
\etocsetlevel{definition}{1}% 'definition' entries will be included
\etocsetlevel{section}{2}%  % sections are hidden
\etocsettocstyle{\section{Foo}}{}%
\etocsetstyle{definition}
{}{}
{\pagebreak[2]\vskip\baselineskip}%
\tableofcontents
}


In order to demonstrate that the normal table of contents is not affected by this - at least not when \etocsetlevel{definition}{6} is called before - I added a dummy section and \tableofcontents to the document below.

The interesting part of the full code that produced the output shown above is this:

\appendix
\listofdefinitions

\section{Bar}
\begin{definition}{Blue}
\lipsum[2]
\end{definition}

\begin{definition}{Argument}
\lipsum[2-3]
\end{definition}


Here's the full code:

\documentclass{article}
\usepackage{parskip}

\usepackage{etoc}

% a simple definition' environment:
\newcounter{definition}
\newenvironment{definition}[1]
{%
\refstepcounter{definition}%
\etoctoccontentsline{definition}{\protect\numberline{#1}}%
}
{\par\bigskip}

% this will display all definitions but nothing else as a toc:
\newcommand\listofdefinitions{%
\setcounter{tocdepth}{1}%
\etocsetlevel{definition}{1}% 'definition' entries will be included
\etocsetlevel{section}{2}%  % sections are hidden
\etocsettocstyle{\section{Foo}}{}%
\etocsetstyle{definition}
{}{}
{\pagebreak[2]\vskip\baselineskip}%
\tableofcontents
}

% use standard toc and hide definition entries
\etocsetlevel{definition}{6}

% dummy text:
\usepackage{lipsum}

\begin{document}

\tableofcontents

\section{Foo Bar}
\subsection{Foo}
\lipsum[1]

\subsection{Bar}
\lipsum[2-4]

\appendix
\listofdefinitions

\section{Bar}
\begin{definition}{Blue}
\lipsum[2]
\end{definition}

\begin{definition}{Argument}
\lipsum[2-3]
\end{definition}

\begin{definition}{Foo}
\lipsum[2]
\end{definition}

\begin{definition}{Bar}
\lipsum[2]
\end{definition}

\begin{definition}{Foo Bar}
\lipsum[2]
\end{definition}

\end{document}

-
I just realized I forgot the \usedef{} requirement... I'll add something but this'll have to wait until tomorrow. – clemens Feb 17 '13 at 21:57
When I use this code I get the following error ! Undefined control sequence. \definition ...r {definition}\etoctoccontentsline {definition} – Alessandro Vermeulen Feb 19 '13 at 12:44
Try updating your TeX distribution. etoc` is rather new and has had a few updates already – clemens Feb 19 '13 at 14:31
Ah that did the trick. However, in my case this doesn't print the definitions in alphabetical order when showing the definitions, only in the index. – Alessandro Vermeulen Feb 20 '13 at 15:59
@AlessandroVermeulen Please see my edited answer – clemens Feb 21 '13 at 21:01