# \index inside \autocite prenote not working

1. I am writing a tex file that uses the package biblatex-chicago and makeidx.
2. I am using endnotes package to push all footnotes to the Notes section.
3. All citations appear in the Bibliography section. This is acheived using \autocite.
4. In the project, I want indexing inside pre- and post-notes of \autocite. Meaning that, in the Index section, a term will correspond to the relevant page in the Notes section. For example, in the following example, "clah" should appear in the Index along with the page number in the Notes section where in appears.

Q The problem I am facing is this- when I put \index in pre-notes it fails to compile. But \index inside post-notes works just fine. Could someone please clarify how to solve this problem?

For example,when I do

\autocite[blah blah][clah clah\index{clah}]{a-citekey}


it works! However,

\autocite[blah blah\index{blah}][clah clah]{a-citekey}


fails to compile.

Here is the MWE:

\def\DevnagVersion{2.16}
\documentclass[11pt]{book}
\usepackage[a4paper,bindingoffset=0.2in,%
left=1in,right=1in,top=1.2in,bottom=1.2in,%
footskip=.5in]{geometry}

\usepackage{makeidx}
\usepackage{endnotes}
\let\footnote=\endnote

\usepackage[notes]{biblatex-chicago}
\renewcommand\nameyeardelim{, }

\usepackage{float}
\usepackage{tabls}
\usepackage{graphicx}
\usepackage{cleveref}
\usepackage{parskip}
\usepackage{devanagari}
\usepackage{epigraph}

\usepackage{fancyhdr, blindtext}
\newcommand{\changefont}{%
\fontsize{8}{10}\selectfont
}
\fancyhf{}
\fancyfoot[C]{\changefont \thepage} %footer
\pagestyle{fancy}

\newcounter{ExCount}
\newcommand{\ex}[1]{
\stepcounter{ExCount}
\subsubsection*{~~ \textit{Example \arabic{ExCount}: #1}}
}
\newcommand{\he}[1]{
\subsubsection*{#1}
}

\DeclareAutoCiteCommand{endfull}[f]{\footfullcite}{\footfullcites}
\ExecuteBibliographyOptions{autocite=endfull}

\sloppy

\title{A catchy title}
\author{Author One \and Author Two}

\makeindex

\begin{document}
\maketitle\newpage
\tableofcontents\newpage

\frontmatter

\chapter{Intro}

Testing the Wendy Doniger example from Penguin.\footcite[][p. 65]{doniger1999splitting}

This line is just to test index.\autocite[please refer to][for a detailed analysis{\index{analysis}}]{a-citekey}

% but this does not work
% This line is just to test index.\autocite[please   refer\index{refer} to][for a detailed analysis]{a-citekey}

\newpage
\def\enotesize{\footnotesize}
\cleardoublepage
\theendnotes

\renewcommand*{\bibfont}{\footnotesize}
\printbibliography

\cleardoublepage
\printindex

\end{document}


Here is the content of the bibfile question.bib

@book{doniger1999splitting,
title =        {Splitting the difference: Gender and myth in ancient
Greece and India},
author =       {Doniger, Wendy},
year =         {1999},
publisher =    {University of Chicago Press},
location =     {Chicago}
}

@InCollection{a-citekey,
author =       {Author One},
title =        {A long title: this is a really long title},
booktitle =    {This is my book: proud to have written this},
publisher =    {Elite Publishing House},
year =         2006,
editor =       {A bigshot editor},
chapter =      7,
}

• Thank you Duck Dodgers for the edit. Much clearer now. I appreciate it :) – Kusan Biswas Aug 5 '19 at 10:52

Use

\protect\index{<term>}


instead of \index{<term>} in pre- and postnotes.

Depending on the style and the settings biblatex may apply additional formatting or other macros to the pre- and postnote fields. It may happen that the field contents are expanded in such a way that unexpandable macros cause issues. That's why you are on the safe side protecting uses of \index in pre- and postnotes with \protect even if it does not appear necessary on first glance.

\documentclass{article}
\usepackage{makeidx}
\usepackage{biblatex-chicago}

\makeindex

\begin{document}
Testing the Wendy Doniger example from Penguin.\autocite[65]{sigfridsson}

This line is just to test index.\autocite[refer][analysis\protect\index{analysis}]{sigfridsson}

This line is just to test index.\autocite[refer\protect\index{refer}][analysis]{sigfridsson}

\printbibliography

\printindex
\end{document}


In case of biblatex-chicago prenotes are problematic because of \MakeCapital in

\DeclareFieldFormat{prenote}{\ifcapital{\MakeCapital{#1}}{#1}\isdot}


With standard biblatex \index in postnotes is problematic because of \mkpageprefix and \mknormrange in

\DeclareFieldFormat{postnote}{\mkpageprefix[pagination][\mknormrange]{#1}}


• Thanks a lot @moewe ! You rock! \protect solves the problem. – Kusan Biswas Aug 6 '19 at 6:03
• Sorry I forgot to accept. Done now. – Kusan Biswas Aug 6 '19 at 6:10