This is an excerpt of the book “Better Books with LaTeX.” The book comes with a LaTeX template you can use to easily create your own books.

As opposed to their electronic counterparts, printed books do not have a search functionality to find specific words in the text. Instead, they have an index at the end as a service for the reader to quickly find certain parts of the book that he or she wants to read. If you are planning to only write an e-book version of your book, you can skip this section—e-books do not have indexes because they do not have fixed page numbers: they are formatted differently on different devices.


Did you know?


While an index for e-books is not needed, it can help tremendously with finding keywords for advertisement purposes. -→ Read more in Writing Better Books, the Agile Way


Unfortunately, there is no easy way of generating an index automatically—at least not in the quality a human can. Why is that?

Beyond simply listing all the concepts in a book, a good index is like an intelligent filter. The person creating the index has to think about what a reader might search for and list that word, even though it might never literally appear in the book. Likewise, if a concept consists of multiple words, it might be good to include both variations, for example “language → mathematics” and “mathematics → language” to refer to the language of mathematics and mathematics as a language.

But how can LaTeX help in this regard? In traditional book-making, creating the index of a book is a separate process after the actual book is finished. You can imagine it basically as having the printed book in front of you, then going through page by page, noting which concepts appear on a particular page. This approach gets problematic if you want to make changes to the book that affect the page numbers: you would have to redo the entire index each time.

 Indexing in Word

Figure 5.1:Marking an entry to add it to the index in Microsoft Word.

Word and LaTeX address each this issue in its own way. In Word, you can select the word or words you would like to use as an index entry, and click on Mark Entry (on the References tab, in the Index group). A dialog shows up (see Figure 5.1) where you can configure the index entry (search for “Create and update an index” to find Microsoft Office help on this topic). Once done, Word switches into the hidden symbol mode that shows things like line breaks or index entries which are usually hidden. In that regard, Word switches into a kind of hybrid mode, and you no longer “see what you get.” If you want to edit an index entry, you have to edit the code, for example “Mathematics{*XE*”language:mathematics”*}.”

  Indexing in LaTeX

In LaTeX, you insert the command in a straightforward way by adding the \index{…} directly into the text. For example, if you have the sentence “Mathematics is a language” you could add two indexes: “Mathematics\index{mathematics} is a language\index{language}.”

The big question is: which words should you index? Before we address that, let us look at an overall indexing strategy. Myself, I am using this one:

First, index all the terms that need to be indexed no matter what. Those are:

  • People names. Whenever you mention (or quote) a person, add the index command behind his or her name. The format for indexing people names is “\index{last name, first name middle name},” for example, “\index{Darwin, Charles Robert}.”
  • Media titles. Likewise, whenever mentioning a work of art (book, movie, software, etc.), it needs to be added at this position. If you mention the title directly, use “\index{title of the work@{title of the work}}”. Preferably, use the previously discussed “\citetitle{bibid}”: “\{@\citetitle{bookid}}”. The “bibid” stands for the id you have given in the bibliography file. The “@”-character is necessary for the indexing engine to recognize the italic font formatting. The exception to this rule would be titles that start with an article (a, the) which is usually put at the end (e.g., Last Unicorn, The instead of The Last Unicorn).
  • Concept definitions. When introducing a concept and providing its definition (especially in glossary items), this is a place a reader might want to look first. For indexing, you can mark those indexes in bold by adding “—textbf”: “\index{word—textbf}”. For example:
     
    Science\index{science|textbf} is the formalized process of gaining new knowledge.
                                                             
                                                             
          
    
  • Captions. Do not index entries in captions of figures. This will cause problems during compilation. Instead, index the place where the figure is referenced in the text.

Once those basics are implemented, you move into the second phase. Now go from paragraph to paragraph and ask yourself each time what concepts this paragraph discusses.

It is not enough that a word is mentioned, the paragraph should explain something about the word or concept in question. Imagine the reader looking up the word in the index, going to the page, and then wanting to read what the word in question is about. For example, take the sentence “A republic is different than a democracy as it sets the constitution as its highest arbiter.” Of course you would index “republic” in this sentence. But if you also indexed “democracy,” a reader will gain no value from it. From the sentence, the reader does not get any explanation of what democracy is about. If the sentence was “A republic is different than a democracy as it puts the constitution, not the people, as its highest arbiter,” the situation would be different. It is not a definition of democracy, so you would not mark it as bold in the index, but the sentence describes what democracy is. Alternatively, you can also always use more general concepts in an index. Here, you could use “systems of government” instead of either republic or democracy, especially when you are just comparing different systems of government in that paragraph. Even if you never use the expression “system of government” in your book, a reader will be satisfied reading the paragraph as—at least in its content—it compares systems of government. As the following phases will only remove or combine indexes, it is safe to “overindex” in this second phase. You can even add multiple index entries for individual words. Using the example from above, you could add both “republic” and “systems of government.”

Once you are done with indexing individual words, in phase three, you can take a break and have your editor (or a friend) take the role of a reviewer. Alternatively, take a longer break and revisit your book one month later with a fresh mind. For the review, go one by one through the index, go to the page specified, and ask yourself if the paragraph really explains the concept. If not, remove it.

Phase four then deals with cleaning up this “overindexed” index. Look at the index and see if you can find entries that can be combined. For example, you might find you have the following entries in your index: “Greek alphabet”, “Latin alphabet”, and “Phoenician alphabet.” Here you have to ask yourself if your readers search for “alphabet” or already have a specific language in mind. In my book “Philosophy for Heroes: Knowledge ,” I decided for the former and combined the index into “alphabet, Greek”, “alphabet, Latin”, “alphabet, Phoenician.” This categorization can be done in LaTeX with the following construct:

\index{main category!sub category}. In our case: “\index{alphabet!Greek}”, “\index{alphabet!Latin}”, and “\index{alphabet!Phoenician}” respectively. You can also go one level deeper, although that should be the exception. For example, you could categorize “natural numbers in mathematics” as \index{mathematics!number!natural}. In both cases, LaTeX will automatically combine those three entries and arrange them together.

With this in mind, I recommend reading a few indexes of the books in your library to learn how the authors combined their concepts. In addition, if you want to know more about the theory of knowledge and categorization of language and in philosophy, check out Philosophy for Heroes: Knowledge which explains it in detail.

Next, you might want to explain to the reader that two different words in the index actually refer to the same concept. Maybe there is a popular expression for something and (in your field of work) the correct expression for something. In the index, you can point one expression to the other.

For example, one application is when citing a person who has different names, maybe a real name and an artist name. Readers might look for either version of the name. For example, the mathematicianLeonardo Bonacci is also known as Fibonacci. You might list both names and tell the reader that he is referring to the same person. If you used “Leonardo Bonacci” in your text, you can add an index with the following format: \index{one version of the word—see{other version of the word}}. In our case this would be “Leonardo Bonacci was a famous mathematician.\index{Bonacci, Leonardo}\index{Fibonacci—see{Bonacci, Leonardo}}”. Another example and a bit of an inside joke would be recursion: “If a statement relates to itself, it is called recursive.\index{recursion}\index{recursion—see{recursion}}”

Finally, read through the entire index again and check for spelling mistakes. These are common if your main tool of proofreading is the PDF or a printout because the index commands are hidden. The most common mistakes are having some index entries in singular form and some in plural, mixing British and American English, or having some expressions with and some without hyphens.

That is it!

Here again are the steps of the index creation as a list:

1.
Index all the basic terms (titles, people names, definitions).
2.
Go through the entire text and index all the terms that are explained in a particular paragraph.
3.
Check all indexes by going backwards from the index to the text.
4.
Combine indexes into groups.
5.
Check books with similar topics and get ideas based on how the authors did their indexing.
6.
Add references from one index to another (e.g., for people with several names).
7.
Check for spelling errors.