Is there any way to auto-gererate an index for the makeidx package? I've written ~270 pages and didn't think of adding \index{} everywhere.

Do I really need to go over everything and add \index{}?

  • 2
    What words should be indexed? If they are marked in some way (\cs{word}) you can modify the definition of \cs. Otherwise I'm afraid that there's only one way.
    – egreg
    Jun 10 '12 at 13:16
  • Related: tex.stackexchange.com/questions/54518/…
    – lockstep
    Jun 10 '12 at 13:17
  • @egreg, Ideally I would want to have a file that specified keywords that was extraced from the text. So I could remove/add to that. Jun 10 '12 at 13:21
  • 5
    @FilipEkberg: This process could be simplified by the search and replace function of your editor. Jun 10 '12 at 13:25
  • 1
    Also related: tex.stackexchange.com/questions/856/…
    – Caramdir
    Jun 10 '12 at 16:11

Do I really need to go over everything and add \index{}?

Unfortunately yes. At best even if you write a script to automate it you will end up with a concordance, and a concordance is not an index.

In my opinion it is actually better to postpone the writing of the index to the time the book is almost ready. Writing an index is an art and most publishers employ "human indexers" to write an index that is useful and serves its function.

Since luckily, you missed it the first time round this is a good time to give it a bit of a thought and planning, before you delve into it.

The most important points to consider when developing an index, is categorization and consistency. Think of the likely readers of your book (or even the older you that will forget what the younger you wrote) and provide headings that are likely to be used when searching for information. Consider for example a historical book, describing early ships and their trade routes. It can be meaningless for example to just index the ship name by one word. Consider the following MWE:

\DeclareRobustCommand{\ship}[1]{\textit{#1}\index{Steam ships!#1}}
\DeclareRobustCommand{\AUports}[1]{\textit{#1}\index{Austalia ports!#1}}
  One of the early steam ships to sail to \AUports{Melbourne} 
  was the \ship{Africa}. Its maiden trip was on the 1.1.1870 and 
  its last trip ten years later on the 13.12.1880. 

I have used a heading to categorize the ship as a steam ship (you can add macros as necessary) and provided a second one to classify Melbourne as a port. By creating a number of commonly used categories around your topic you can also ensure that you have a good classification system as well as providing consistency. As you might have probably noticed the ship's name is typeset in italics, to comply with the Oxford Style Guide and by creating a macro both the indexing as well as the typesetting are done correctly and efficiently.

  • Could you maybe give me some pointers on how to write a good index? And maybe what pitfalls that I would have gone into? What I've done now is that I've looked up keywords and "concepts" that I talk about and adding a corresponding index to that paragraph/page. Jun 10 '12 at 19:21
  • 2
    @FilipEkberg It is getting a bit late here, but I will post some pointers tomorrow. Jun 10 '12 at 20:05
  • 2
    @FilipEkberg Please see edit. Jun 12 '12 at 8:13
  • 1
    @FilipEkberg No the word in the example is a ship name and hence the italics. For most it will be normal upshape text. Jun 15 '12 at 9:42
  • 1
    Thanks for this solution. Note, if you run the MWE above here the ship name is in monospace as the wrong formatting command, i.e. \texttt{} instead of \textit{} in the \DeclareRobustCommand{\ship}. Sorry for apparent pedantry but the MWE is confusing, especially if you don't know where the italics are (supposedly being set.
    – mwra
    Jun 11 '20 at 14:54

I know this is an old thread, but I want to mention that I have just released a piece of software to address this problem. It isn't perfect, but as a "semi-automatic" solution it is a lot faster than going through with a text editor and adding the \index{} tag one at a time. It contains one program that reads your LaTex file and uses various heuristics to suggest terms that should be in an index, and another problem to rapidly browse through your LaTex file and insert the terms. It is GPL and you can download for free at https://sourceforge.net/projects/indexmeister/

The same page also has a link to a short YouTube video tutorial I made showing how the software is used. Hopefully, it will be useful to someone. I'm already using it in-house in my small publishing company.

  • 1
    Welcome to TeX.SX! Thank you for sharing your solution. Could you please show with an example how it works? Having the link is certainly great, but the readers would benefit a lot from a concrete example. Dec 11 '15 at 19:52
  • 3
    Usage example from the command line: To generate a list of suggested words and phrases to index: indexmeister example.tex > terms.txt To browse through the list of terms, seeing all occurrences in the project (i.e. every .tex file in the working directory), with the ability to rapidly insert tags: imbrowse terms.txt The second program has an interactive menu-driven interface, I have a video and screenshots on the Sourceforge page. Dec 13 '15 at 4:22
  • 1
    Is this GitHub repo yours: github.com/longhunt/indexmeister ? Is this where current development is occurring, or is development continuing at the SourceForge page?
    – Geremia
    Apr 20 '18 at 22:30

Here is a simple Python solution: https://github.com/themoodymann/IndexTex. It indexes definitions, captions, theorems, and emphazised words in all .tex files that are stored in a directory.

  • Welcome to tex.sx. This is an interesting suggestion, but if a term that ought to be indexed isn't already emphasized or marked as something special (theorem, etc.), it won't be included. So there could still be quite a bit of manual work left. Mar 21 '20 at 16:06

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.