I am trying to generate an index of person names, which are used in a book.
On its first appearance, the person is introduced using it complete name (i.e. name and surname and maybe an additional explanation), later on in the text, only the persons name will be used.
I intended to use good old makeindex to generate the index, as there is no other index needed. Therefore I wrote macros, one for the initial appearance of the person, one for all further appearances. The initial appearance macro uses name and surname as mandatory arguments, the second macro uses only the name as mandatory argument.
I thought, it would be clever, to write the names via the \index
-command using the @
like this \index{#2@#2}
(assuming, the persons name is always stored in #2, its surname in #3). So, for the initial appearance the index will look like this:
\index{#2@#2, #3}
And this is the call for further appearances:
\index{#2}
Unfortunately, Makeindex won't identify those as unique names. Even when I changed the second macro to use the @
also:
\index{#2@#2}
will show up as an second entry of the same name.
What went wrong, what must I change?
Here is the MWE:
\documentclass[a4paper]{scrartcl}
\usepackage[main=english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{makeidx}
\usepackage{ifthen}
%% Definition of macros
%% Initpers is used, when the person is first mentioned. It takes 4
%% arguments:
%% #1: Output in the text (optional)
%% #2: Name (mandatory)
%% #3: Surname (mandatory)
%% #4: Description (mandatory but most of the time empty)
%%
\newcommand{\initpers}[4][]{%
% output the name and surname into the text. If the optional
% argument #1 is given, use this, else use the mandatory arguments
% #2 and #3
\ifthenelse{\equal{#1}{}}{
{#3 #2}}{%
#1}%
% Now, insert Name, Surname and the Description (if given) into the index.
\ifthenelse{\equal{#4}{}}{%
\index{#2@#2, #3}}{%
\index{#2@#2, #3 (#4)}}%
}%
%% This macro shall be used, whenever a person, which was already
%% introduced, shall be mentioned again. In this case, only the name
%% is used.
\newcommand{\pers}[1]{%
% output the name into the text, enter it into the index.
% #1\index{#1}
#1\index{#1@#1}%
}%
% generate the index
\makeindex
\begin{document}
This is some text, in which I will reflect on the book ``The two
cultures'' by \initpers{Snow}{Charles Percy}{}. This book \dots
%% For the sake of this example, lets assume, we mention Mr. Snow
%% later on
\newpage
This was also mentioned by \pers{Snow} as described earlier.
\printindex
\end{document}
This is the unfortunate result, because, it contains two entries of Mr. Snow, despite the fact, that this is one person and should be listed as Snow, Charles Percy, 1, 2:
Snow, Charles Percy
should appear only once although occuring twice (in your MWE)? Thinking about this, I feel you should useglossaries
rather than the plainmakeidx
here. The@
has a special meaning for makeindex as a sorting indicator, which is possibly not what you want hereSnow, Charles Percy
only once but listing two page numbers in this case.