13

I'm creating an index using makeindex and I can't get the output to look the way I want. Basically, I would like to create an entry formatted as follows:

entry1
~~~subentry1, 2
~~~subentry2, 3
~~~see also entry2

I can't figure out how to format the \index command so that the last line appears properly. The best I've come up with is \index{entry1!z@{}|seealso{entry2}}, but starts the entry off with a comma.

Anyone else encounter this incredibly specific and OCD problem?

EDIT: Ok, here's an example that demonstrates the issue:

\documentclass[12pt]{memoir}
\makeindex

\begin{document}

Lorem ipsum
\index{entry1!subentry1}
\index{entry1!subentry2}
\index{entry1!z@{}|seealso{entry2}}

\printindex
\end{document}  
1
  • Well, \renewcommand*\seealso[2]{\subitem \emph{\alsoname} #1} will force the 'seealso' macro to start a new 'subitem', but the that will sort under '\emph' and therefore ahead of virtually all sub-entries.
    – jon
    Dec 12, 2012 at 4:31

3 Answers 3

15

Here's a mild hack that inserts a gobble macro in the index file to discard the ,:

enter image description here

\documentclass[12pt]{memoir}% http://ctan.org/pkg/memoir
\makeindex
\makeatletter
\newcommand{\gobblecomma}[1]{\@gobble{#1}\ignorespaces}
\makeatother
\begin{document}

Lorem ipsum
\index{entry1!subentry1}
\index{entry1!subentry2}
\index{entry1!subentry3@\gobblecomma|seealso{entry2}}

\printindex
\end{document}

The index file after running makeindex resembles:

\begin{theindex}

  \item entry1
    \subitem subentry1, 1
    \subitem subentry2, 1
    \subitem \gobblecomma, \seealso{entry2}{1}

\end{theindex}

clearly showing that it gobbles the comma, but would also remove any following spaces (via \ignorespaces). The use of subentry3@\gobblecomma is to accurately place the "comma gobbler" alphabetized to subentry3.

3
  • 1
    Perhaps you should make it clearer that 'subentry3' is used in this case to make sure it follows 'subentry2' and 'subentry1' (whereas 'subentry' would put it first). For general purposes, it would probably be better to write \index{entry1!zzz@\gobblecomma|seealso{entry2}}.
    – jon
    Dec 12, 2012 at 6:00
  • Bingo. That solved my problem. Thanks everyone!
    – Evan
    Dec 13, 2012 at 1:03
  • @Evan: You could consider marking the answer as such. See How do you accept an answer?
    – Werner
    Dec 13, 2012 at 1:07
6

barbara beeton's answer, unfortunately, places a comma before "see also" for some reason. Alas, it is easy to combine the two answers (barbara's and Werner's) to get to the desired result with a convenient command.

define once:

\newcommand{\gobblecomma}[1]{\ignorespaces}
\providecommand{\indexalso}[2]{%
    \index{#1!zzzzz@\gobblecomma|seealso{#2}}}

use:

\indexalso{<main heading>}{<see-also heading>}

example:

\index{entry1!subentry1}
\index{entry1!subentry2}
\indexalso{entry1}{entry2}

will output (as desired):

entry1
~~~subentry1, 2
~~~subentry2, 3
~~~see also entry2
3
  • +1, but \newcommand{\gobblecomma}[1]{\ignorespaces} is simpler.
    – egreg
    Oct 4, 2015 at 9:31
  • I don't think this “simpler” command works anymore :/ For some reason, the | is gobbled instead of the comma. This solved the issue. Jan 20, 2016 at 0:18
  • It works fine until now!
    – M. Logic
    Jun 1, 2022 at 10:30
5

i think it's easiest to create an entirely new command:

\providecommand{\indexalso}[3]{%
  \index{#1!zzzzz@\emph{\alsoname} {#2}}}

i've used \providecommand rather than \newcommand as this is a candidate for inclusion in the ams document classes, and it's not polite to cause old files to suddenly generate errors when a class change like this is known ahead of time.

\indexalso would be used like this:

\indexalso{<main heading>}{<see-also heading>}

the zzzzz ensures that this will be listed last, unless an author has a really odd second-level entry. if multiple "see also"s are to be used, they should all be included in the single \indexalso entry:

\indexalso{<main heading>}{<see-also heading; another see-also>}

i've been writing up some tips on how to produce a "clean" index, including everything i've had to answer questions about for ams publications; your question came at just the right time, since this is problem was still on the "todo" list.

after consulting in-house editorial staff and the chicago manual, we've determined that, for ams books, the style you request is best -- and that's what will be recommended in our indexing document. i'll be posting the document on the ams web site when it's released, and will add the link here when that happens.

You must log in to answer this question.

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