12

I'm creating an index using makeidx. When I have a "see also" cross-reference in an entry, I want it to appear after the listing of page numbers. But instead it appears before the listing.

Here's what the output currently looks like:

quantifiers see also numbers, cardinal, 2

Here's what I want the output to look like:

quantifiers 2, see also numbers, cardinal

Is there a straightforward way to change this behavior, say, in my index style file?

1
  • 2
    Given that the output is supposed to be the latter, based on what indexing professionals do, I'm sort of surprised that isn't the default.
    – kcrisman
    Commented Jun 28, 2019 at 20:55

2 Answers 2

10

The order is controlled by the page number. The feature "see" is implemented as encapsulating command:

\index{quantifiers|textbf}% bold page number
\index{quantifiers|see{numbers, cardinal}}%

Makeindex appends the page number, thus the following macro is called in \printindex:

\textbf{1} and \see{numbers, cardinal}{1}

The implementation of \see ignores the page number, but Makeindex sorts the page numbers. With them, the page numbers and see statements are sorted.

The following example defines \indexsee{<index entry>}{<see entry>} that writes the index entry with a quite large page number to sort it at the end. Also the page number is increased each time to avoid warnings of Makeindex, if it sees different encapsulating commands for the same entry.

Macro \index reads it argument in verbatim mode. Therefore \indexsee should do the same to avoid different outcome of the same index keys (more less spaces, expansion, ...).

\documentclass{article}
\usepackage{makeidx}
\makeindex

\makeatletter
\newcommand*{\indexsee}{%
  \@bsphack
  \begingroup
  \@sanitize
  \@wrindexsee
}
\newcommand*{\@wrindexsee}[2]{%
  \stepcounter{indexsee@page}%
  \protected@write\@indexfile{}{%
    \string\indexentry{#1|see{#2}}{\the\value{indexsee@page}}%
  }%
  \endgroup
  \@esphack
}
\newcounter{indexsee@page}
\setcounter{indexsee@page}{10000}
\makeatother

\begin{document}
Hello
\index{numbers, cardinal}
\index{numbers, funny}
\indexsee{quantifiers}{numbers, funny}
\newpage
World
\index{quantifiers}
\newpage
\null
\indexsee{quantifiers}{numbers, cardinal}
\printindex
\end{document}

Result

File test.idx, written by the LaTeX run:

\indexentry{numbers, cardinal}{1}
\indexentry{numbers, funny}{1}
\indexentry{quantifiers|see{numbers, funny}}{10001}
\indexentry{quantifiers}{2}
\indexentry{quantifiers|see{numbers, cardinal}}{10002}

File test.ind, generated by Makeindex:

\begin{theindex}

  \item numbers, cardinal, 1
  \item numbers, funny, 1

  \indexspace

  \item quantifiers, 2, \see{numbers, funny}{10001}, 
                \see{numbers, cardinal}{10002}

\end{theindex}
1
  • I have to remark that the book "Indexing for Editors and Authors" by the American Society of Indexers (yes! there is such a thing!) specifically says "A see reference will never have locators." But I presume your solution would work with some modification for seealso?
    – kcrisman
    Commented Jun 28, 2019 at 20:54
4

We could use Xindy for this task, the order of location classes is in our favor and can be used right away. We run some LaTeX engine, e.g.:

lualatex mal-xindy-see.tex
xindy -M texindy -L general -C utf8 mal-xindy-see.idx
lualatex mal-xindy-see.tex

% run: *latex mal-xindy-see.tex
% xindy -M texindy -L general -C utf8 mal-xindy-see.idx
% and *latex again
\documentclass[a4paper]{article}
\pagestyle{empty}
\usepackage{makeidx}
\makeindex
\begin{document}
Text before.
\index{numbers, cardinal}
\index{numbers, funny}
\newpage
\index{quantifiers}
\index{quantifiers|see{numbers, funny}}
\index{quantifiers|see{numbers, cardinal}}
Text after.
\begingroup
\def\thispagestyle#1{}
\printindex
\endgroup
\end{document}

mwe

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .