Is it possible to insert an index at the beginning of a document, like so?:

\makeindex[name=definitions,title=Definitions,columns=1,intoc=true,program=makeindex,options={-s index_style.ist}]


bla bla \index[definitions]{bla}, lorem ipsum \index[definitions]{ipsum}


FYI the content of index_style.ist is:

headings_flag 1
heading_prefix "{\\large\\bfseries "
heading_suffix "}\\nopagebreak\n"
delim_0 " \\dotfill "
delim_1 " \\dotfill "
delim_2 " \\dotfill "
  • You can't have the automatically generated index at the beginning; for this you need to pass the noautomatic option and run makeindex manually. – egreg Oct 7 '13 at 15:56
  • Is there a way to automate the process? – idle Oct 7 '13 at 16:00
  • 1
    With arara, certainly. – egreg Oct 7 '13 at 16:41

You have to call imakeidx with the nonewpage option and run makeindex manually.

Unfortunately, there's also the need to apply a patch around a bug that should be solved in the next release of imakeidx; see Why does imakeidx + nonewpage fail to write an idx file?

In order to automate the work you have two roads:

  1. Use latexmk

  2. Use arara

I'd prefer the latter, as it's more easily customizable.

Example (thanks to Paulo Cereda, arara's author, for suggesting the files trick).

% arara: pdflatex
% arara: makeindex: { files: [definitions], style: index_style.ist}
% arara: pdflatex

% work around the bug. :(
%%% The following two lines are incorrectly switched in the package
    \immediate\closeout\csname #1@idxfile\endcsname
  \let\imki@indexname\indexname % keep \indexname
  \if@tempswa % we can call the external program
  \let\indexname\imki@indexname % restore \indexname
%%% end of bug fix

  options={-s index_style.ist}]


bla bla \index[definitions]{bla}, lorem ipsum \index[definitions]{ipsum}


If you run arara -v filename, you'll get this output.

enter image description here

There is a reason for the standard imakeidx automation not being possible in this case: in order to run makeindex, the .idx file(s) must be closed and contain all the required entries, which is not possible if the indices are not at the end of the document. The .idx files written during the previous run are not available any more, because the \makeindex declaration opens them (emptying them as a consequence) at begin document.


latexmk filename

should work out of the box (with the patch).

  • When will the patch be available on CTAN? – idle Oct 8 '13 at 18:36
  • @idle Soon, sure. – egreg Oct 8 '13 at 19:44

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.