5

I'm trying to include an index at the end of my document using \usepackage{imakeidx} and the \makeindex and \printindex commands.

I would like the index to mention the section number as well, for instance:

37. Section 37 Make a mention of the word index

Index

index, s37, p1

Is this possible, and if yes, how?

1
  • Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. Commented Jun 29, 2014 at 3:47

1 Answer 1

6

Using xindy as index generator, it is possible to write additional information to index file, such as the section number s37,p100 or similar.

The relevant command is imki@wrindexentrysplit, the format can be specified in its 3rd argument, see the lines there.

However, xindy does not recognize this format initially, so there has to be an additional xindy module, the usage of it is specified within the options=-M sectionindex_sectionpage.xdy option to \makeindex.

I used a forloop to generate some dummy sections with dummy index entries, just for convenience. The index shows the format s{sectionnumber},p{pagenumber} .

\documentclass[paper=a4,12pt]{scrartcl} \usepackage{blindtext}% \usepackage{fmtcount}% \usepackage{forloop}% \usepackage[xindy]{imakeidx}% \makeatletter % Global redefinition of indexentry to use section, then page% \renewcommand{\imki@wrindexentrysplit}[3]{% \expandafter\protected@write\csname#1@idxfile\endcsname{}% {\string\indexentry{#2}{s\arabic{section},p\thepage}}% }% \makeatother \makeindex[options=-M sectionindex_sectionpage.xdy] \begin{document} \newcounter{loopcounter} \forloop{loopcounter}{1}{\number\value{loopcounter} < 13}{% \section{Section \Numberstring{loopcounter}} \blindtext \vspace{\baselineskip} This is a dummy index entry to \textbf{\Numberstring{loopcounter}}\index{\Numberstring{loopcounter}} } \printindex \end{document} 

The file sectionindex_sectionpage.xdy contains

( require "tex/inputenc/latin.xdy") ( require "texindy.xdy" ) ( require "page-ranges.xdy") ( require "book-order.xdy") ( define-location-class "sectionfirstthenpages" ("alpha" :sep "" "arabic-numbers" :sep "," "alpha" :sep "" "arabic-numbers" )) 

enter image description here

3
  • can this be done without xindy? just using package index using makeindex. If put \label for each section and put \ref{thatsectionlabel} in index arument it works..but i have many sections in a large document Commented May 20, 2015 at 19:35
  • @LevanShoshiashvili: I don't know at the moment, I'll take a look later on Commented May 21, 2015 at 4:21
  • This seems to break linking when using \usepackage{hyperref}. Does anyone know of a way make both work together? Commented Aug 15, 2021 at 23:00

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.