In my textbook, I want to include both an index and a glossary. For the glossary, for which I'm currently using the glossaries package, I would prefer to have pointers (and hyperlinks) that don't go straight to one or more occurrences in the main text, but instead point to a single index entry (typically for the same term).

Maybe a sketch is in order.

Conventional scenario:

    Combustion engine -> page 23, page 56, ...

    Combustion engine: an endangered species -> page 23, page 56, ...

What I would like instead:

    Combustion engine -> page 23, page 56, ...

    Combustion engine: an endangered species. -> (page of) index entry 
                                                 on combustion engine

And while we are at it, we might as well also generate a pointer to the glossary entry within the index item.


  1. No cluttering up the glossary with potentially long lists of page references that are already maintained in the index.

  2. I usually give fairly extensive explanations in the glossary entries themselves, and the main text typically does not add much to those; thus, I don't want to frustrate the reader by inviting him to sift through the main text in search of detail that isn't there.

  3. While writing, I don't want to think about questions like: should this occurrence go into the index only, the glossary only, or both? Thinking about what to include in the index is distraction enough.

PS: Before commenting on the above sample text, note that the book is about neither engines nor endangered species.


Here is what I came up with: I ditched the glossaries package and instead implemented a couple of macros based directly on hyperref. The index is generated as usual by makeindex, but I use a few tricks in order to let it generate the hyperlinks and -targets to match the ones created in the glossary. The glossary can simply be written as a description environment (although in real life I would use the enumitem package to customize it).

% arara: pdflatex
% arara: makeindex
% arara: pdflatex
% arara: pdflatex

% we need two pdflatex runs after makeindex for this to work. 
% arara is great for this kind of per-document build configuration. 



% create a custom style file for makeindex that wraps the standard 
% index item commands such that we can get hold of their text contents
% e.g:
% \inx{drugs}
%     \subinx{lithium}\hyperpage{2}, \hyperindexformat{\glsitem}{3}
%     \subinx{molecular size}\hyperpage{1}

line_max        2048

item_0 "\n\\inx{"
item_1 "\n    \\subinx{"
item_01 "\n    \\subinx{"
item_x1 "}\n    \\subinx{"
item_2 "\n        \\subsubinx{"
item_12 "\n        \\subsubinx{"
item_x2 "}\n        \\subsubinx{"

delim_0 "}"
delim_1 "}"
delim_2 "}"

% load and run makeindex

% we use hyperref to implement the reciprocal links between glossary and index

% implement the commands

% raise hypertargets by one line to get them into the viewport

% a glossary entry. Mandatory arguments are term and definition. 
% The optional argument becomes a prefix for the index key. 
    \item [#2] \raisedtarget{gls-#2} #3 \hyperlink{inx-#2}{\pageref*{inx-#2}\emph{i}}

% wrap the index \item and \subitem commands to store the current index term
    \item #1 

    \subitem #1 

    \subsubitem #1 

% format the index page references generated by glossary entries  
    \label{inx-\currentinx}% we need the label to typeset the index page in the glossary ...
    \raisedtarget{inx-\currentinx}% ... and the explicit hypertarget to make the link work


\section{Introduction to pharmacology}

... document text snipped ...    



% the [drugs!] prefix makes the link go to a subitem in the index
\glsentry[drugs!]{lithium}{An alkali metal used in batteries that moonlights as an antidepressant}

% no prefix will point the link to a main index item
\glsentry{Paracelsus}{A famous physician from the 16th century who investigated the relationship of drugs and poisons by way of self-experimentation}




The glossary looks like this:

enter image description here

The index like this:

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.