3

I have a question similar to this question: I'm using makeidx and I want the index to use a different counter than \thepage. My code looks like this:

\documentclass{scrbook}

\usepackage{makeidx}
\usepackage{xpatch}

\makeindex

\newcounter{NewCounter}

\setcounter{NewCounter}{5}

\makeatletter % the macro name contains @

\xpatchcmd{\@wrindex}{%
   \indexentry{#2}{\thepage}%
   }{%
   \indexentry{#2}{\NewCounter}%
   }
  {}{}% <success> and <failure> code not needed

\makeatother

\begin{document}

\stepcounter{NewCounter}\chapter{Test}\index{Test}
\arabic{NewCounter}

\printindex

\end{document}

So, unfortunately after compilation with lualatex and makeindex the entry "Test" has the pagenumber (1) instead of the NewCounter (6) in the index. Any help with the usage of xpatchcmd? Thanks in advance.

2

I found a way to do it with imakeidx. For all who are interested:

\documentclass{scrbook}

\usepackage{imakeidx}

\newcounter{NewCounter}

\setcounter{NewCounter}{5}

\makeatletter
\newcommand{\Index}[1]{\imki@wrindexentry{MyIndex}{#1}{\theNewCounter}}
\makeatother

\makeindex[name=MyIndex]

\begin{document}

\stepcounter{NewCounter}\chapter{Test}\Index{Test}
\arabic{NewCounter}

\printindex[MyIndex]

\end{document}

I defined an own index command \Index. The idea is pretty much given in the documentation of imakeidx p. 15.

  • Is very important to add an image of your work. +1 for you. – Sebastiano May 30 '18 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.