3

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 "
3
  • Perhaps you would get more responses if you said exactly how you compile this document. In any case, writing \index[m]{cought Cathy's cold@\gls{ccc}} will give the correct placement of the index entry. I don't the glossary package well enough to find out how to generate that text automatically though. Jan 14, 2022 at 14:52
  • To include your ist file in your MWE, you can use \begin{filecontents*}{index_style.ist}
    – JeT
    Jan 14, 2022 at 15:49
  • @AndrewSwann - thanks! I'm using Overleaf, so whichever way Overleaf compiles is what I use. @JeT Thanks - I'm quite new to LaTeX. I'll have a closer look at how to include the ist file in my MWE using your tip and update my question after.
    – Parvana
    Jan 17, 2022 at 8:13

1 Answer 1

1
+50

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.

1
  • Unfortunately not a complete solve, because when I do in fact delete the @\gls{...} portion, the entry in the index (in the PDF) no longer links to the glossary. My wish is still to keep that link intact, but not to have the index page appear in the glossary entry.
    – Parvana
    Jan 17, 2022 at 13:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .