(Note: This is somewhat related similar post, but the issue is quite different.)
I'm trying to make an index entry using \index
that has a bolded page number, all while the hyperref
package is loaded. Normally when hyperref sees a manually-inserted |textbf
in an index entry it will do something clever like modify or remove the usual |hyperpage
insertion. That's fine. No problem.
The trouble lies when I try to first parse argument of \index
using the macro \comma@parse
from the kvsetkeys
package, as shown here:
%with hyperref is loaded, this produces a bad .idx entry
\comma@parse{But this fails on makeindex|textbf}{\index{\comma@entry}\@gobble}
The code above produces the following entry in the .idx file:
\indexentry{But this fails on makeindex|textbf|hyperpage}{1}
As you can see, there are two |
symbols in the entry, causing the makeindex
to reject it. hyperref
should have caught this.
- If I disable hyperref, everything works fine.
- If I don't use the
\comma@parse
macro, everything works fine. - The same thing happens if instead of
|textbf
I do|see
etc.
It's as if using \comma@parse
doesn't allow hyperref
to do its job.
Is there a way I can get the .idx
entry to be well-formed while keeping hyperref loaded?
Here's the MWE I'm using:
\documentclass[12pt]{book}
\usepackage{makeidx}\makeindex
\usepackage{lipsum}
\usepackage{kvsetkeys}
\usepackage{hyperref}
\begin{document}
\lipsum[1]
\index{1@This works fine|textbf}
\makeatletter
\comma@parse{2@So does this}{\index{\comma@entry}\@gobble}
\comma@parse{3@But this fails on makeindex|textbf}{\index{\comma@entry}\@gobble}
\makeatother
\printindex
\end{document}
And here's the .idx
file that is created after typesetting:
\indexentry{This works fine|hyperindexformat{\textbf}}{1}
\indexentry{So does this|hyperpage}{1}
\indexentry{But this fails on makeindex|textbf|hyperpage}{1}