Skip to main content
To create an alphabetical index in LaTeX, load makeidx (or imakeidx), call \makeindex in the preamble, mark terms in the body with \index{term}, and place \printindex where the index should appear. Compile the document with pdflatex, run makeindex on the generated .idx file, and run pdflatex again to insert the sorted index.

Basic index setup

\makeindex opens a <jobname>.idx file during compilation and writes each \index{...} entry along with its page number. \index{...} prints nothing in the body text; attach it directly to the indexed word without an intervening space so TeX cannot insert a page break between the word and its marker. \printindex reads the sorted <jobname>.ind file produced by makeindex and typesets a two-column Index section (or chapter in book and report).
index-basic.tex
Ready to use this syntax? Continue in the browser editor when you want to adapt the example in a real project.Open LaTeX Cloud Studio
When the same term is indexed on multiple pages—such as LaTeX on pages 1 and 2 above—makeindex merges them into a single entry with comma-separated page numbers.

Subentries, custom sort keys, and special characters

makeindex reserves four punctuation characters inside \index{...} to control hierarchy, sorting, formatting, and escaping: Use ! to group related terms under a main heading; makeindex supports three levels (\item, \subitem, and \subsubitem). Use @ whenever the displayed entry contains math mode, formatting commands, or macros whose raw characters would sort out of alphabetical order—for example, \index{LaTeX@\LaTeX} sorts under LaTeX instead of the backslash. To include a literal !, @, |, or " in an entry, prefix it with ".
subentries-sort.tex

Page ranges, formatted page numbers, and cross-references

Append | followed by an operator to mark multi-page discussions, style individual page numbers, or point readers to another heading: Write the formatting macro name after | without a leading backslash (|textbf, not |\textbf), because makeindex automatically prepends \ when writing the .ind file. Both makeidx and imakeidx define \see and \seealso, which discard the entry’s page number and print the cross-reference label instead.
ranges-crossrefs.tex

Choosing between makeidx and imakeidx

  • makeidx is a small package in the standard LaTeX base distribution (makeidx.sty). Because \makeindex and \index live in the LaTeX kernel, makeidx only adds \printindex, \see, and \seealso. It leaves running makeindex to your build tool or command line and uses your document class’s default index layout.
  • imakeidx extends \makeindex with key-value options such as title=... (custom heading), columns=... (number of columns), intoc (adds the index to the table of contents), and name=... for maintaining multiple indexes in one document. When TeX runs with restricted or unrestricted shell escape enabled, imakeidx invokes makeindex automatically during the LaTeX pass. If you compile with -no-shell-escape or pass \usepackage[noautomatic]{imakeidx}, automatic execution is disabled and you run makeindex externally; add the quiet package option (\usepackage[noautomatic,quiet]{imakeidx}) to suppress imakeidx’s end-of-run reminder warning.
imakeidx-options.tex

Build sequence

Locally on the command line, building an index takes three passes (or four if intoc adds the index to the table of contents):
You can also pass just the base name (makeindex main), or let latexmk run makeindex and the follow-up LaTeX passes automatically:
LaTeX Cloud Studio compiles with TeX Live 2026 (full distribution), so both makeidx and imakeidx are pre-installed.

Common mistakes

  • Forgetting \makeindex in the preamble: Without \makeindex, LaTeX ignores \index{...} calls and writes no .idx file; \printindex then prints nothing under makeidx and stops with Package imakeidx Error: Misplaced \printindex. under imakeidx.
  • Forgetting to run makeindex: On the first pass before makeindex runs, LaTeX logs No file main.ind. and skips the index without failing. Run makeindex main.idx and recompile.
  • Running imakeidx under -no-shell-escape: Disabling shell escape turns off imakeidx’s automatic makeindex call and logs Package imakeidx Warning: Remember to run (pdf)latex again after calling with `makeindex main.idx' and or call (pdf)latex with -shell-escape.. Run makeindex externally (or use latexmk), and pass [noautomatic,quiet] if you want a clean log.
  • Adding a backslash after |: Writing \index{term|\textbf} makes makeindex output \\textbf{1} in the .ind file, which breaks the line and prints literal textbf1. Always omit the backslash (\index{term|textbf}).
Ready to add an index to a book or long report? Start from the Book template in LaTeX Cloud Studio and replace main.tex with the complete example.