How can I add every glossary entry to the index?
Quick solution
Here is a shorter solution, it struggles with the issue that it writes the first occurence text to the glossary.
\defglsdisplayfirst[\acronymtype]{#1#4\index{#1}}
It redefines the first display of the term to include a call to index using the \defglsdisplayfirst
command and restricts this change to the acronym glossary.
Right now the issue with this is that #1
is already defined to long term (acronym)
, but for normal glossary entries it should be just fine.
A workarround might be to redefine the new acronym command to set the description differently. But in the long run it would be nice to simply have access to the label in the \defglsdisplay(first)
command to access the other keys as needed. I wrote a feature request to nicola.
From Nicloas response to the feature request:
If one uses \glslabel
one can access all the other information. Thus for acronyms use \index{\glsWhatKeyDoYouWantForTheIndex{\glslabel}}
instead.
Primitive solution
I had a similar problem and deduce the awnser from that. I redefine the glossary command to call index as some of the awnsers in the related questions suggest, however the call to ìndex`is only made when its the first use.
\documentclass{article}
\usepackage{makeidx}
\makeindex
\usepackage[acronym]{glossaries}
\makeglossaries
\newacronym{gpu}{GPU}{graphics processing unit}
\let\oldGls\gls
\renewcommand{\gls}[1]{%
\ifglsused{#1}{ %
\oldGls{#1}%
}{%
\oldGls{#1}%
\index{\glsentryfirst{#1}}%
}%
}
\begin{document}
%\gls{gpu}
First use \gls{gpu}-computing\\
subsequent \gls{gpu}-computing and \gls{gpu}
\clearpage
\gls{gpu}
\printindex
\end{document}
I only covered the \gls
-command, and did not check for the glossary the entries are in, this could cause trouble if you have multipleglossaries.
Indexing the entries inside printglossary
By using a custom style for printglossary one can add the index commands.
\documentclass{article}
\usepackage{makeidx}
\makeindex
\usepackage{hyperref}
\usepackage{glossaries}
\makeglossaries
\newglossaryentry{gpu}{name=graphics processing unit, description={bla blup}}
% \defglsdisplayfirst[acronym]{#1#4\index{#1}}
\newglossarystyle{myList}{%
\glossarystyle{list}%
\renewcommand*{\glossaryentryfield}[5]{%
\item[\glsentryitem{##1}\glstarget{##1}{##2}\index{\glsentrytext{##1}}]
##3\glspostdescription\space ##5}%
\renewcommand*{\glossarysubentryfield}[6]{%
\glssubentryitem{##2}\index{\glsentrytext{##1}%
\glstarget{##2}{\strut}##4\glspostdescription\space ##6.}%
}}
\begin{document}
First use \gls{gpu}-computing
\clearpage
\printglossary[type=main, style=myList]
\printindex
\end{document}
Simply go to your texmf tree, take a look at the style you want to use, and copy its definitions of \glossaryentryfield
and \glossarysubentryfield
out. create your own style be writing (place the index call at a reasonable point, otherwise you could use patch \appendto
):
\newglossarystyle{yourStyle}{%
\glossarystyle{originalStyle}%
\renewcommand*{\glossaryentryfield}[5]{originalDef+\index{\glsentrytext{##1}}}%
\renewcommand*{\glossarysubentryfield}[6]{originalDef+\index{\glsentrytext{##1}}}%
}
Ok, after struggling with this myself I came up with the following short solution. It does require minimum hacking but requires you to use \mygls{ABBRV} when you want the index generated.
\providecommand{\myglsindextext}[1]{\glsentrydesc{#1} (\glsentrytext{#1})}
\providecommand{\myglsindex}[1]{\index{\myglsindextext{#1}}}
\providecommand{\mygls}[1]{\gls{#1}\myglsindex{#1}}
\providecommand{\myglspl}[1]{\glspl{#1}\myglsindex{#1}}
\providecommand{\myGls}[1]{\Gls{#1}\myglsindex{#1}}
\providecommand{\myGlspl}[1]{\Glspl{#1}\myglsindex{#1}}
hih