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.
-
Will you only have one reference to the item (at it's first usage/definition)? – Werner Dec 14 '11 at 22:27
-
1Have a look at How to create an index for custom environments?, if you really mean something like a table of contents. Otherwise you could clarify if you mean an index, a glossary or nomenclature, because there are packages for this. – Stefan Kottwitz Dec 14 '11 at 22:27
-
1Which documentclass do you use? Please provide a minimal example. – Marco Daniel Dec 14 '11 at 22:28
-
You don't have to mention LaTeX in the title. It's the default on this site. What you mean is normally called list-of-X or maybe an index. – Martin Scharrer Dec 15 '11 at 00:11
2 Answers
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}

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}
- 505,128
-
Thnx for the nice solution! Is it somehow possible to sort the
listofdefinitionsbefore printing it? – Skip Dec 15 '11 at 12:28 -
@Skip: if you want to sort the entries, perhaps you could better consider using a package such as nomencl. – Gonzalo Medina Dec 15 '11 at 14:44
@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}
- 11,742