6

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. enter image description here

1 Answers1

6

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:

enter image description here

\documentclass{article}
\usepackage{parskip}

\usepackage[colorlinks]{hyperref}
\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}
    {}{}
    {\noindent\etocnumber\strut\leaders\etoctoclineleaders\hfill\etocpage\par}
    {\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}

Original answer

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...

enter image description here

I define a simple definition environment:

\newcounter{definition}
\newenvironment{definition}[1]
  {%
    \refstepcounter{definition}%
    \etoctoccontentsline{definition}{\protect\numberline{#1}}%
    \par\noindent\textbf{#1}\quad
  }
  {\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}
    {}{}
    {\noindent\etocnumber\strut\leaders\etoctoclineleaders\hfill\etocpage\par}
    {\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[colorlinks]{hyperref}
\usepackage{etoc}

% a simple `definition' environment:
\newcounter{definition}
\newenvironment{definition}[1]
  {%
    \refstepcounter{definition}%
    \etoctoccontentsline{definition}{\protect\numberline{#1}}%
    \par\noindent\textbf{#1}\quad
  }
  {\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}
    {}{}
    {\noindent\etocnumber\strut\leaders\etoctoclineleaders\hfill\etocpage\par}
    {\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}
cgnieder
  • 66,645
  • I just realized I forgot the \usedef{} requirement... I'll add something but this'll have to wait until tomorrow. – cgnieder 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 – cgnieder 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 – cgnieder Feb 21 '13 at 21:01
  • sorry for the late reply, but how did you obtain the pdf you show? I tried with running pdflatex, makeindex and again pdflatex on the file I stored your code in. makeindex tells me this: "Scanning input file definitions.tex...done (0 entries accepted, 65 rejected). Nothing written in definitions.ind." The last text in the resulting PDF is the chapter header "A Foo". – Alessandro Vermeulen Feb 27 '13 at 10:10
  • @AlessandroVermeulen You need to run makeglossaries instead of makeindex – cgnieder Feb 27 '13 at 10:24