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}}}%
}
\newacronym
internally uses \newglossaryentry
and has an optional argument that can be used to add any extra keys that the entry requires. There are two possible approaches. The first is to use child entries:
\documentclass{book}
% Abbreviations
\usepackage[acronym,nonumberlist,
nopostdot,% Remove the dot at the end of glossary descriptions
style=tree,% use hierarchical style
toc]{glossaries}
\makeglossaries
\renewcommand*{\acronymname}{List of Abbreviations}
\newglossaryentry{time}{name=Time,description={}}
\newacronym[parent=time]{utc}{UTC}{Coordinated Universal Time}
\newacronym[parent=time]{adt}{ADT}{Atlantic Daylight Time}
\newglossaryentry{cities}{name=Cities,description={}}
\newacronym[parent=cities]{la}{LA}{Los Angeles}
\newacronym[parent=cities]{ny}{NY}{New York}
\begin{document}
\frontmatter
\printglossaries
\mainmatter
\chapter{Introduction}
% Use the acronyms
\gls{utc} is 3 hours behind \gls{adt}.
\gls{ny} is 3 hours ahead of \gls{la}.
\end{document}
This produces:
In this case the glossary style must be one that supports hierarchical entries, so I've chosen the tree
style for the MWE. See the Predefined Glossary Styles table in the user manual for other options (the maximum level needs to be 1 or more, but should not be one of the homograph styles).
The second approach is to define different glossaries and use the type
key. For example:
\documentclass{book}
\usepackage[nonumberlist,
nopostdot,% Remove the dot at the end of glossary descriptions
style=tree,% change as appropriate
toc]{glossaries}
\newglossary{time}{gls2}{glo2}{Time}
\newglossary{cities}{gls3}{glo3}{Cities}
\makeglossaries
\newglossaryentry{sample}{name=sample,description={an example}}
\newacronym[type=time]{utc}{UTC}{Coordinated Universal Time}
\newacronym[type=time]{adt}{ADT}{Atlantic Daylight Time}
\newacronym[type=cities]{la}{LA}{Los Angeles}
\newacronym[type=cities]{ny}{NY}{New York}
\begin{document}
\frontmatter
\printglossary
\chapter{List of Abbreviations}
\setglossarysection{section}
\printglossary[type=time]
\printglossary[type=cities]
\mainmatter
\chapter{Introduction}
\gls{utc} is 3 hours behind \gls{adt}.
\gls{ny} is 3 hours ahead of \gls{la}.
\gls{sample} entry.
\end{document}
This puts the main
glossary in a chapter (assuming you want that) but the two abbreviation glossaries are placed in sections. The result looks like:
The style no longer needs to be one that supports child entries, so you can change it to whatever is suitable.
Best Answer