# How do I prepare an index of symbols with memoir?

I want to prepare an index of symbols for a book I'm writing (using the memoir class). There is an obvious problem of how you order the symbols. Since many of them are non-alphabetic, I think that the order of appearance in the book is the best idea. I skimmed through the man page for makeindex, but didn't find any option for that (and I don't want to do things like \index{01@symbol}, \index{02@symbol} etc., for obvious reasons).

Bonus points for a solution where non-alphabetic symbols appear first (as a group), sorted in the order of appearance, and alphabetic ones after them, sorted lexicographically, like in

Symbols
=
<
(,)

A
angle
apple
arrgh

B
Banach space
banana

• Do something like \index{aaaaaaa\arabic{symbolcounter} @\somesymbol}\stepcounter{symbolcounter}? Sep 18 '14 at 14:49
• Thanks! I thought about it, too, but some time after posting the question. It might work, and if there's no package doing this, I'll probably end up writing one. ;) Sep 18 '14 at 15:53
• Ha, I found out that my question is mostly duplicate of tex.stackexchange.com/q/41140/5626 . Sep 18 '14 at 15:55
• Under that post egreg explained "hAB" without an implement. And Marc van Dongen gave an answer producing duplicated symbol-items. Sep 18 '14 at 16:05
• What do you mean by "duplicated"? (I didn't test the solutions there.) Sep 18 '14 at 16:15

Something like this? Explaination

• \newsymbol{cos} gives this symbol ($\cos$) an unique id (= current value of symbolcounter). This number is stored in the macro symbolidofcos.
• \symbolindex{cos} check whether this symbol appeared before. If not, it does \newsymbol{cos}. It then, no matter the symbol being new or old, writes informations into the index.
• Symbols will be sorted according to their ids. Since ids are given in sequences, symbols will be shown in the order of their first appearances.

Here is the code

\documentclass{memoir}
\usepackage{makeidx}
\makeindex
\newcounter{symbolcounter}\setcounter{symbolcounter}{1000}
\newcommand*\newsymbol{
\stepcounter{symbolcounter}
\expandafter\edef\csname symbolidof#1\endcsname{\arabic{symbolcounter}}}
\newcommand*\symbolindex{
\ifcsname symbolidof#1\endcsname\else\newsymbol{#1}\fi
\index{~@(Symbols)!\csname symbolidof#1\endcsname @$\csname#1\endcsname$}}
\begin{document}
\index{Lorem}
$\sin\theta$\symbolindex{sin}
\index{ipsum}
$\cos\theta$\symbolindex{cos}
\index{dolor}
$\tan\theta$\symbolindex{tan}
\index{sit}
\clearpage
\index{amet}
$\cos\phi$\symbolindex{cos}
\index{consectetur}
$\cosh\phi$\symbolindex{cosh}