4

This is a very general question, but I would like to make and index for my thesis, that indexes any word that I bf in the documents, and references the page number next to it. I am using the makeidx package.

I just need the command to work it. Thanks guys!

2 Answers2

7

Instead of the package hvindex, I use this command \dfn in some documents:

%% \dfn[index entry]{defined term}
\newcommand{\dfn}[2][]{\textbf{#2}%
  \ifthenelse{\equal{#1}{\empty}}{\index{#2}}{\index{#1}}}

It highlights the mandatory parameter, i.e. the defined term, in bold and indexes it unless an optional parameter is provided which would take precedence. There are more advanced techniques in makeidx, of course, which ar enot supported by this convenient macro.

I would advise against renewcommanding \textbf.

Crissov
  • 1,866
7

As noted in Best practice for index construction -- recommendations and references, constructing an index requires time, dedication, and skill, and should almost certainly not be automated- the results could lead to a useless index.

However, the following code does what you requested: it makes an index entry for every entry that is contained in the textbf command.

Note, in particular, the arara directives at the top of the document; to compile the document (say, myfile.tex), simply run

arara myfile

Here's the complete code:

% arara: pdflatex
% arara: makeindex
% arara: pdflatex

\documentclass{article}
\usepackage{makeidx}

\let\oldtextbf\textbf
\renewcommand{\textbf}[1]{%
\oldtextbf{#1}%
\index{#1}
}
\makeindex
\begin{document}

\textbf{my text}

\clearpage
\textbf{another}
\printindex
\end{document}
cmhughes
  • 100,947