1

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]
\usepackage[colorlinks=true]{hyperref}

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

4
  • 1
    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.
    – egreg
    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.
    – user143670
    Sep 17 '17 at 21:04
  • 1
    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).
    – user143670
    Sep 17 '17 at 21:19
0

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[colorlinks=true]{hyperref}
\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}{%
  \DTLifdbexists{list}{\DTLcleardb{list}}{\DTLnewdb{list}}% Create new/discard old list
  \pagebreak
  \chapter*{Table des symboles}
  \addcontentsline{toc}{chapter}{Table des symboles}
}{%
    \DTLsort*{description}{list}% Sort list
     \DTLforeach*{list}{\theDesc=description, \theItem=item}{%%
     \theItem , \hyperlink{page.\theDesc}{\theDesc}%\theDesc
\\ }% 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:

enter image description here

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

2
  • 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
    – koleygr
    Sep 17 '17 at 21:46
  • Great, many thanks for your proposal! It's way more elaborate that what I'd tried so far ;)
    – user143670
    Sep 17 '17 at 21:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.