14

Is it possible to introduce an own table of contents in LaTeX? I would like to introduce an own tag, to define some terms in my document. At the end of the document I would like to automatically generate a list of defined terms, with links to the page, where the term was defined.

Martin Scharrer
  • 262,582
Skip
  • 1,165
  • 3
  • 12
  • 16

2 Answers2

13

In the following example I defined a \Defi command with two mandatory arguments; the first mandatory argument for the term to be defined and the second one, for the definition; the command typesets the term in boldfaced font, adds the term to the auxiliary file .def, and adds a \phantomsection command (this part requires the hyperref package) to get the proper anchor for the hyperlinks. The command \listofdefinitions will actually create the new "List of Definitions" using the kernel \@starttoc command. In the example the entries of the new list will be formatted as the figures in the LoF, but this can also be customized:

\documentclass{article}
\usepackage{hyperref}

\newcommand\Defi[2]{%
  \noindent\makebox[1.5cm][l]{%
    \textbf{#1}%
    \phantomsection% comment out if hyperref is noy used
    \addcontentsline{def}{figure}{#1}}{#2}\par}

\makeatletter
\newcommand\listdefinitionname{List of Definitions}
\newcommand\listofdefinitions{%
  \section*{\listdefinitionname}\@starttoc{def}}
\makeatother

\begin{document}

\Defi{CDMA}{Code Division Multiple Access}
\Defi{GSM}{Global System for Mobile communication}
\Defi{NAD}{Nicotinamide Adenine Dinucleotide}
\Defi{TDMA}{Time Division Multiple Access}
\Defi{IC}{Integrated Circuit}
\Defi{BUT}{Block Under Test}

\listofdefinitions

\end{document}

enter image description here

Here's a version of the above code using the \newlistof command from the tocloft package:

\documentclass{article}
\usepackage{tocloft}
\usepackage{hyperref}

\newcommand\Defi[2]{%
  \noindent\makebox[1.5cm][l]{%
    \phantomsection% comment out if hyperref is noy used
    \textbf{#1}%
    \addcontentsline{def}{figure}{#1}}{#2}\par}

\newcommand\listdefinitionname{List of Definitions}
\newlistof{definition}{def}{\listdefinitionname}

\begin{document}

\Defi{CDMA}{Code Division Multiple Access}\newpage
\Defi{GSM}{Global System for Mobile communication}
\Defi{NAD}{Nicotinamide Adenine Dinucleotide}\newpage
\Defi{TDMA}{Time Division Multiple Access}
\Defi{IC}{Integrated Circuit}
\Defi{BUT}{Block Under Test}

\listofdefinition

\end{document}
Gonzalo Medina
  • 505,128
1

@Gonzalo Medina: Putting \addcontentsline in \makebox slows down processing. And the abbreviation may sometimes be longer than the fixed 1.5cm you have used.

\documentclass{article}
\usepackage{hyperref}

\makeatletter
\newcommand\Defi[2]{%
  \noindent
  \makebox[\ListOfDefAbbrevLength][l]{\textbf{#1}}%
    \csname phantomsection\endcsname
    \addcontentsline{def}{figure}{#1}%
  {#2}\par
}
\newdimen\ListOfDefAbbrevLength
\ListOfDefAbbrevLength=1.5cm
\newcommand\ListOfDefName{List of Definitions}
\newcommand\ListOfDefinitions{%
  \section*{\ListOfDefName}%
  \@starttoc{def}%
}
\makeatother

\begin{document}

\Defi{CDMA}{Code Division Multiple Access}
\Defi{GSM}{Global System for Mobile communication}
\Defi{NAD}{Nicotinamide Adenine Dinucleotide}
\Defi{TDMA}{Time Division Multiple Access}
\Defi{IC}{Integrated Circuit}
\Defi{BUT}{Block Under Test}

\ListOfDefinitions

\end{document} 
Ahmed Musa
  • 11,742