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

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}

-
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 '12 at 4:31

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

\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.

-
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 '12 at 6:00
Bingo. That solved my problem. Thanks everyone! –  Evan Dec 13 '12 at 1:03
@Evan: You could consider marking the answer as such. See How do you accept an answer? –  Werner Dec 13 '12 at 1:07

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.

-