This is a script to make creating TeX/LaTeX document indexes easier. \index{..} commands will make your content quite unreadable and it is easy to miss terms. reads the index terms from a separate file and produces a version of your LaTeX source which has \index{...} commands in place.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

This python script makes creating TeX/LaTeX document indexes much easier. It takes a LaTeX source and an index terms file, and produces LaTeX source with \index{...} commands inserted.

When you want to create indexes in LaTeX, there are two main difficulties:

  1. \index{...} commands will make the document source quite difficult to read and edit.
  2. It is quite easy to miss locations where a desired index term appears.

Both of these tasks are much easier done by computer rather than by a human. uses an index terms file which has the following syntax (lines starting with # are comments):

# an entry like "term:"  causes "term" to be used as an index term

in effect, the above will cause any appearance of "Python" in the document to be replaced by Python\index{Python}. ignores the case, i.e. "pYthon" will be replaced by "pYthon\index{Python}". Also it will match the term as a prefix. i.e. "pythonized" will be replaced by "python\index{Python}ized".

There are a few other ways to define terms:

# an entry like "term-label:alternative1, alternative2, ..." causes any of the alternatives to be indexed as the same term
agent-based:agent-based,agent based

The above example will index either "agent-based" or "agent based" (or "is-agent-based" or "Agent Based", for that matter) as index entry "agent-based".

# an entry like "label!sublabel:" or "label!sublabel:alternative1, alternative2, ..."
# will create leveled indexes.
Programming!C: C++, objective-c

The above example will create sub-index entries.

You must make sure longer entries which contain others come first. Because texindex will search and replace the terms in the order they appear in index terms file. For example the following is correct: cognitive distance: cognitive:

However, if you instead write: cognitive: cognitive distance:

Then you will not find any "cognitive distance" index terms. Because once the term "cognitive" is taken care of, any instances of "cognitive distance" will be dirty as "cognitive\index{cognitive} distance"; therefore will not find the second term.

Running the program

$ python mybook.tex indexterms.txt > mybookindexed.tex

Multi-part files will replace any appearance of \input{somefile.tex} with the actual contents of the file, prior to creating index terms. Thus it will generate a complete source file for LaTeX projects that are split into multiple source files.