# makeindex - Sorting by page number using many math symbols

I'm trying to create an index of symbols for my thesis by using makeindex and it doesn't work as well as I'd like.

Indeed, I use a lot of math symbols (which means a lot of macros) in my work and I want them to appear by page number.

Unfortunately, they appear by "alphabetical" order, and I've not found a quick way to sort them by page number.

Here is a short MWE :

\documentclass[a4paper, one side, 11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath, amsfonts, amssymb, amsthm}
\usepackage{imakeidx}
\makeindex[title = Table des symboles, columns = 1, intoc]

\begin{document}
\section{More blabla about $\epsilon$}
Blabla $\epsilon$\index{$\epsilon$}
\newpage
\section{More blabla about $\omega$}
Blabla $\omega$\index{$\omega$}
\newpage
\section{More blabla about $\beta$}
Blabla $\beta$\index{$\beta$}
\printindex
\end{document}


The result is :

Table des symboles

β, 3
ε, 1
α, 2


Whereas I'd like :

Table des symboles

ε, 1
α, 2
β, 3


Does anyone know how to solve my problem please ?

Any help would be very appreciated.

• Welcome to TeX.SX! If you have a lot of symbols, how's the reader supposed to find them in the index? Sorting in “alphabetical order” is meant for giving the reader some clue and then the entry points to the page where the symbol is described. A sorting by page number seems quite useless. Sep 17 '17 at 20:55
• Thanks a lot for your quick answer! You may have a point about the interest of sorting by page number in some cases, but since the "alphabetical order" is computed with the names of the macros (here, "alpha", "epsilon" etc.), it isn't of much use either. Since the reader may know more or less when the symbol was introduced, it may help him search the index. Sep 17 '17 at 21:04
• after seeing how many book authors have handled their symbol indexes, i have concluded that in general, a glossary approach is often preferable to an index listing. the most effective presentations i've seen have three elements for each symbol -- the symbol itself, a very brief statement of what it represents, and the page number(s) on which it appears, often with the page where it is defined shown in bold. there are good glossary packages available if you decide to look into this method. Sep 17 '17 at 21:14
• Thanks, in fact it's what've I done, but I hadn't considered switching to a glossary package. However, I'd still like to know if there's a way of forcing the order in general, and by page numbering in particular (it may be done manually, but of course that's not a good solution). Sep 17 '17 at 21:19

You can do it with a sorted list like this:

\documentclass[a4paper, one side, 11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath, amsfonts, amssymb, amsthm}
\usepackage{imakeidx}
\makeindex[title = Table des symboles, columns = 1, intoc]
\usepackage{datatool}
\usepackage{tikz}

\newcounter{myitems}
\let\oldindex\index
\renewcommand{\index}[1]{
\stepcounter{myitems}
\xdef\myitemPage{\thepage}
\xdef\myitem{#1}
\global\expandafter\let\csname ItemPage\themyitems\endcsname\myitemPage
\global\expandafter\let\csname Item\themyitems\endcsname\myitem
\oldindex{#1}
}

\newcommand{\sortitem}[1]{%
\DTLnewrow{list}%
\dtlexpandnewvalue
\DTLnewdbentry{list}{description}{\csname ItemPage#1\endcsname}%
\DTLnewdbentry{list}{item}{\csname Item#1\endcsname}%
}

\newenvironment{sortedlist}{%
\pagebreak
\chapter*{Table des symboles}
}{%
\DTLsort*{description}{list}% Sort list
\DTLforeach*{list}{\theDesc=description, \theItem=item}{%%
\\ }% Print each item
}

\begin{document}
\section{More blabla about $\epsilon$}
Blabla $\epsilon$\index{$\epsilon$}
\newpage
\section{More blabla about $\omega$}
Blabla $\omega$\index{$\omega$}
\newpage
\section{More blabla about $\beta$}
Blabla $\beta$\index{$\beta$}

\begin{sortedlist}
\foreach \i in {1,...,\themyitems}{\sortitem{\i}}
\end{sortedlist}

\printindex %Remove this
\end{document}


Output:

I have used datatool package (for the list) and unnecessary tikz (for the sorting loop -but can change it without usage of tikz if you want-).

Also I have left there the original index list to see it is the same but unsorted.

I have used my answer from here: Alphabetically sort expanding (newcommand/def) list elements and conditional formatting by iteration

• If you don't want to use tikz... you can ask to change the \foreach command to a TeX loop... Also you may need to put a \twocolumn command before printing the list Sep 17 '17 at 21:46
• Great, many thanks for your proposal! It's way more elaborate that what I'd tried so far ;) Sep 17 '17 at 21:48