0

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
mbork
  • 13,385
  • Do something like \index{aaaaaaa\arabic{symbolcounter} @\somesymbol}\stepcounter{symbolcounter}? – Symbol 1 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. ;) – mbork Sep 18 '14 at 15:53
  • Ha, I found out that my question is mostly duplicate of http://tex.stackexchange.com/q/41140/5626 . – mbork 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. – Symbol 1 Sep 18 '14 at 16:05
  • What do you mean by "duplicated"? (I didn't test the solutions there.) – mbork Sep 18 '14 at 16:15
  • if you say \index{cos} twice it produces two "cos"'s in your index. And if you start the counter from 1, you cannot predict which goes first: 1, 13, or 123 – Symbol 1 Sep 18 '14 at 16:16

1 Answers1

1

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[1]{
        \stepcounter{symbolcounter}
        \expandafter\edef\csname symbolidof#1\endcsname{\arabic{symbolcounter}}}
    \newcommand*\symbolindex[1]{
        \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}
    \index{adipiscing}
\printindex
\end{document}
Symbol 1
  • 36,855