In other words, just the way I get a table of contents at the beginning of each chapter with titletoc, I would like to have a word index at the end of each chapter. (In addition to the index for the whole book at the end of the book.)

2 Answers 2


It appears that latexmk can't detect that an idx file has been written via the imakeidx package so "makeindex" isn't run. I placed "makeindex" in quotes because what latexmk actually runs is determined by a Perl variable, $makeindex, and that can be changed in a configuration file. As far as I can tell, if latexmk could detect that the idx file was created via the log file one need only set the $makeindex variable to run splitindex (which splits the index and runs makeindex on each split) with the appropriate argument. I'd get in touch with John Collins, the maintainer of latexmk, and discuss the what has to be done with him.

PS: the splitindexmk engine for TeXShop that I wrote is really a fudge that takes advantage of the fact that latexmk does nothing. Basically it first runs pdflatexmk (an TeXShop engine using latexmk), then splitindex and finally a single run of pdflatex with appropriate options so that TeXShop can sync properly and also Go

  • It is unbelievable that such a desirable feature has never been addressed or implemented. I came expecting for a simple default built in command and was schocked!
    – ulilaka
    Nov 9, 2021 at 18:04

Here's a prototype using the imakeidx package.


%%% Allocate enough chapter indices
  \advance\count255 by 1
    \noexpand\makeindex[name=\number\count255 chap,title=Word index for Chapter \number\count255]}\x
%%% A global index

%%% The user level macros
  \index{#1}% global index
  \expandafter\index\expandafter[\thechapter chap]{#1}%
  % We want the index as an unnumbered section
  % Also disable the page break
  % Print the index
  \expandafter\printindex\expandafter[\thechapter chap]%




First\gindex{first} and abc\gindex{abc}



Second\gindex{second} and def\gindex{def}




We can't use the automatic features of imakeidx that can work only if the indices are the last thing in the document (or, more precisely, nothing to be indexed follows one of the indices), so the procedure is to call

pdflatex filename
splitindex filename
pdflatex filename

Image of Chapter 1

enter image description here

Image of Chapter 2

enter image description here

Image of the global index

enter image description here

Appendix: how to add an engine to TeXShop for building this file

  1. Navigate in the Finder opening the folder ~/Library/TeXShop/Engines (where ~ stands for your Home.

  2. Duplicate the XeTeX.engine file.

  3. Rename the newly created file to splitindex.engine.

  4. Right click on this file and choose "Open with TeXShop.app"

  5. Change the entire contents of the file with

    #! /bin/bash
    splitindex "$bfname"
  6. Save the file and quit TeXShop

On reopening TeXShop the dropdown menu next to the Typeset button will have an entry called splitindex

enter image description here

When you want to run splitindex, just select the item from the dropdown menu and push the Typeset button. This is equivalent to running the command

splitindex filename

I talked before of. For the next typesetting, choose your default engine from the menu, be it LaTeX or Latexmk.

  • Didn't expect such a fast answer so I don't have the time to try right now. I don't understand where the smaller "Chapter" heading comes from but I guess a bit of experimenting will let me find out. In any case, very grateful regards. schremmer
    – schremmer
    Jan 21, 2013 at 18:00
  • 1
    Couldn't resist trying. The pdf doesn't show any index. Looked at imakeidx doc but to no avail. I don't know how to enter the console properly here but some of it is: Chapter 2. No file Stack-2chap.ind. [3] [4] No file Stack-Stack.ind. Package imakeidx Warning: Remember to run (pdf)latex again after calling (imakeidx) `splitindex' and processing the indices. I tried to use pdflatexmk (which I always use) but no change. I am using TeXLive2011 under OSX10.5.8 on a PPC. Best regards.
    – schremmer
    Jan 21, 2013 at 19:45
  • 1
    @schremmer You don't call makeindex; it's splitindex that takes care of that.
    – egreg
    Jan 21, 2013 at 20:16
  • 1
    @schremmer The easiest way is to use the Terminal, or adding an "engine" to TeXShop. Perhaps there's a way to tell latexmk to do this, but it surely involves writing a custom dependency file. If you open the Terminal, go to the working directory and launch splitindex filename, this should be all that's needed.
    – egreg
    Jan 25, 2013 at 17:00
  • 1
    @schremmer Load showidx before imakeidx; but I'm afraid the version of imakeidx coming with TeX Live 2011 is not compatible with showidx; full compatibility has been added in the last version.
    – egreg
    Jan 29, 2013 at 23:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .