I'm working on a book project which is divided in several parts and chapters. At the end of some chapters (let's say at the end of chapter 2 and 3) I want an index which lists all the keyword mentioned since the last index.
The output should look like this
\documentclass{book}
\usepackage{blindtext}
\usepackage{imakeidx}
\makeindex[name=1]
\makeindex[name=2]
\begin{document}
\part{My Headline}
\chapter{My Headline}
\blindtext[2]
\index[1]{Aaa}\index[1]{Bbb}\index[1]{Caa} % keywords for INDEX 1
\chapter{My Headline}
\blindtext[2]
\index[1]{Aaa}\index[1]{Ddd}\index[1]{Eee} % keywords for INDEX 1
\printindex[1] % INDEX 1
\chapter{My Headline}
\index[2]{Aaa}\index[2]{Ddd}\index[2]{Fff} % keywords for INDEX 2
\printindex[2] % INDEX 2
\end{document}
The problem is that the book is already written and I don't want to change all \index{} commands to \index[1]{} or \index[2]{} manually. The idea is to redefine the \index{} command depending on the chapter number.
I'm looking for something like:
\if \thechapter < 3
\renewcommand{\index}{\index[1]}
\else
\renewcommand{\index}{\index[2]}
\fi
The code above doesn't work and I don't know why.
My file looks now like this
\documentclass{book}
\usepackage{blindtext}
\usepackage{imakeidx}
\makeindex[name=1]
\makeindex[name=2]
% here is something missing like:
%
% \if \thechapter < 3
% \renewcommand{\index}{\index[1]}
% \else
% \renewcommand{\index}{\index[2]}
% \fi
\renewcommand{\index}
\begin{document}
\part{My Headline}
\chapter{My Headline}
\blindtext[2]
\index{Aaa}\index{Bbb}\index{Caa} % keywords for INDEX 1
\chapter{My Headline}
\blindtext[2]
\index{Aaa}\index{Ddd}\index{Eee} % keywords for INDEX 1
\printindex[1] % INDEX 1
\chapter{My Headline}
\index{Aaa}\index{Ddd}\index{Fff} % keywords for INDEX 2
\printindex[2] % INDEX 2
\end{document}


\if \thechaptercan't work and even if it would work, at the time of writing the command it does not what you want – Aug 04 '16 at 07:23