Combination hyperref, imakeidx and glossaries: not sure how to get desired effect

glossarieshyperrefimakeidxkoma-scriptscrbook

When I embed a glossary entry as part of the argument for the index (example here: \index[m]{\gls{ccc}} ), the index groups the entry under 'symbols', rather than the begin letter of the glossary entry (in the case of the following MWE the 'c'). How do I prevent this?

My reason for creating this kind of index-entry is that the hyperref package then makes the index entry in the PDF clickable, which then takes me directly to the glossary. However, the unintended side effect is that the glossary then also references the page number of the index. How do I avoid this?

This is the MWE – note, there's a index_style.ist file below that is needed too.

\documentclass[10pt, paper=156mm:235mm, BCOR=12mm, headings=optiontotocandhead, headings=openany]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage[dutch,british,UKenglish]{babel}
\KOMAoptions{headings=small}

\DeclareTOCStyleEntry[
  linefill={},
]{tocline}{chapter}

\makeatletter
\newcommand \Dotfill {\leavevmode \leaders \hb@xt@ 0.75em{\hss .\hss }\hfill \kern \z@}
\makeatother

\newcommand{\toclineinsert}[3][14mm]{%
    \Dotfill #2\makebox[#1][l]{#3\Dotfill}%
}

\usepackage[splitindex]{imakeidx}%Indexing package
\makeindex[intoc,options= -s index_style.ist,name=m,title=\mbox{Index},columns=2]

\usepackage[T1]{fontenc}
\usepackage{Alegreya,AlegreyaSans} 
\renewcommand*\oldstylenums[1]{{\AlegreyaOsF #1}}

%hyphenation
\pretolerance=4000
\tolerance=2000 
\emergencystretch=8pt

\usepackage[hidelinks, bookmarksopen=false]{hyperref}

\usepackage[toc]{glossaries}

\makeglossaries

    \newglossaryentry{aaa}
    {
        name=ate all apples,
        description={I did. I ate all apples and I liked it. But now my tummy hurts and I regret my decision}
    }
    
    \newglossaryentry{bbb}
    {
        name=bought both boxes,
        description={Yes, that's true. Why just buy the one if you can afford both? That's what I thought. However, now my wallet's empty, and so are my boxes}
    }

    \newglossaryentry{ccc}
    {
        name=caught Cathy's cold,
        description={Could have been worse though. It was really just a cold. Cathy and I are going to be OK}
    }

\begin{document}

\frontmatter
\tableofcontents

\addchap[tocentry={\emph{Preface}}, head={\textsc{preface}}]
  {Preface}
  
  I \gls{ccc} last Wednesday. \lipsum

\mainmatter

\addchap[tocentry={Exaltation \toclineinsert{\normalfont{17 December}}{} },head={}]{Exaltation}

I \gls{aaa} and I \gls{bbb}\index[m]{\gls{ccc}}.

\backmatter

\printglossary

\printindex[m]

\end{document}

working together with the index_style.ist file:

headings_flag 1

heading_prefix "\n\\raggedright\\large\\sffamily\\normalfont%
\\noindent\\textbf{"heading_suffix "}\\par\\nopagebreak\n"

item_0 "\n \\item \\small "

delim_0 " \\Dotfill "
delim_1 " \\Dotfill "
delim_2 " \\Dotfill "

Best Answer

Andrew Swann showed how to get the index entry to show up correctly. The next step is to have the glossary text automatically, which we can do with \glsentrytext{ccc}. \index[m]{\glsentrytext{ccc}@\gls{ccc}} still shows up under symbols, unfortunately. The final step is to expand \glsentrytext{ccc} before \index sees what's going on:

I \gls{aaa} and I \gls{bbb}
\expandafter\index\expandafter[\expandafter m\expandafter]\expandafter{\glsentrytext{ccc}@\gls{ccc}}.

If you're going to be doing that often (more than zero times), it might be useful to make that into a command:

\newcommand{\indexgls}[1]{\expandafter\index\expandafter[\expandafter m\expandafter]\expandafter{\glsentrytext{#1}@\gls{#1}}}

and then you can have
I \gls{aaa} and I \gls{bbb}\indexgls{ccc}.

And if you don't want the index page to appear in the glossary entry, you can just delete the @\gls{...} portion.

Given that there's expansion strangeness happening, that command would probably be simpler with LaTeX3, but I don't know that well enough.

Related Question