I would like to sort the index entries independent of case.
Initially I was getting (code provided in MWE) the image on the left. So, that seemed like an easy fix: just apply \lowercase (uncomment the \def in the MWE) but that yields the image on the right:

So, how do I get these sorted alphabetically, and get the two entries for zero to be displayed as a sub-entries under a single heading?
Failed Attempts:
I thought this was an explansion issue, so I tried to use
\edef\LowerCaseWord{\lowercase{#2}} \index{\LowerCaseWord!#1}but this also yielded results identical to the image on the right.
Since a wise member here (who I think no longer wants to be associated with this comment :-)) once alluded that a few carefully placed
\expandafters should fix anything I tried this and it also does not change the output:\edef\LowerCaseWord{\lowercase{#2}} \expandafter\index{\LowerCaseWord!#1}
Code:
%\def\UseLowercase{}% Uncomment to use lowercase
\documentclass{article}
\usepackage{imakeidx}
\ifdefined\UseLowercase% Select whether we use lowercase or not
\newcommand{\IndexTitle}{Index (lowercase)}%
\else
\newcommand{\IndexTitle}{Index}%
\renewcommand{\lowercase}[1]{#1}%
\fi
\newcommand*{\AddIndexEntry}[2]{%
% #1 = indexed term, #2 = word to index this under
\par\noindent
Indexing: #2
\index{\lowercase{#2}!#1}
}%
\makeindex[title={\IndexTitle},columns=1]
\begin{document}
\AddIndexEntry{aardvark}{aardvark}
\AddIndexEntry{Saved by Zero}{Saved}
\AddIndexEntry{Saved by Zero}{Zero}
\AddIndexEntry{zero}{zero}
\printindex
\end{document}
\lowercaseisn't expandable, so no amount of\expandaftercan do. But there's something that can be done. Be patient. :) – egreg Apr 12 '12 at 19:22